ApplicationRef

A reference to an Angular application running on a page.

      
      interface ApplicationRef {
  componentTypes: Type<any>[]
  components: ComponentRef<any>[]
  isStable: Observable<boolean>
  viewCount
  bootstrap<C>(componentOrFactory: ComponentFactory<C> | Type<C>, rootSelectorOrNode?: any): ComponentRef<C>
  tick(): void
  attachView(viewRef: ViewRef): void
  detachView(viewRef: ViewRef): void
}
    

属性

属性说明
componentTypes: Type<any>[] 只读

Get a list of component types registered to this application. This list is populated even before the component is created.

components: ComponentRef<any>[] 只读

Get a list of components registered to this application.

isStable: Observable<boolean> 只读

Returns an Observable that indicates when the application is stable or unstable.

viewCount 只读

Returns the number of attached views.

方法

Bootstrap a new component at the root level of the application.

bootstrap<C>(componentOrFactory: ComponentFactory<C> | Type<C>, rootSelectorOrNode?: any): ComponentRef<C>
      
      bootstrap<C>(componentOrFactory: ComponentFactory<C> | Type<C>, rootSelectorOrNode?: any): ComponentRef<C>
    
参数
componentOrFactory ComponentFactory | Type
rootSelectorOrNode any

可选. 默认值是 undefined.

返回值

ComponentRef<C>

使用说明

Bootstrap process

When bootstrapping a new root component into an application, Angular mounts the specified application component onto DOM elements identified by the componentType's selector and kicks off automatic change detection to finish initializing the component.

Optionally, a component can be mounted onto a DOM element that does not match the componentType's selector.

Example
@Component({selector: 'my-app', template: 'Hello World'}) class MyApp { } const myPlatformFactory = createPlatformFactory(platformBrowserDynamic, 'myPlatform'); myPlatformFactory().bootstrapModule(MyApp);
      
      @Component({selector: 'my-app', template: 'Hello World'})
class MyApp {
}

const myPlatformFactory = createPlatformFactory(platformBrowserDynamic, 'myPlatform');
myPlatformFactory().bootstrapModule(MyApp);
    

Invoke this method to explicitly process change detection and its side-effects.

tick(): void
      
      tick(): void
    
参数

没有参数。

返回值

void

In development mode, tick() also performs a second change detection cycle to ensure that no further changes are detected. If additional changes are picked up during this second cycle, bindings in the app have side-effects that cannot be resolved in a single change detection pass. In this case, Angular throws an error, since an Angular application can only have one change detection pass during which all change detection must complete.

Attaches a view so that it will be dirty checked. The view will be automatically detached when it is destroyed. This will throw if the view is already attached to a ViewContainer.

attachView(viewRef: ViewRef): void
      
      attachView(viewRef: ViewRef): void
    
参数
viewRef ViewRef
返回值

void

Detaches a view from dirty checking again.

detachView(viewRef: ViewRef): void
      
      detachView(viewRef: ViewRef): void
    
参数
viewRef ViewRef
返回值

void