填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写Home

AfterContentInit

一个生命周期钩子,它会在 Angular 完全实例化了指令的所有内容之后调用。 定义一个 ngAfterContentInit() 方法来处理额外的初始化任务。

A lifecycle hook that is called after Angular has fully initialized all content of a directive. Define an ngAfterContentInit() method to handle any additional initialization tasks.

      
      interface AfterContentInit {
  ngAfterContentInit(): void
}
    

参见

方法

一个回调方法,它会在 Angular 初始化完该指令的所有内容之后立即调用。 在指令初始化完成之后,它只会调用一次。

A callback method that is invoked immediately after Angular has completed initialization of all of the directive's content. It is invoked only once when the directive is instantiated.

ngAfterContentInit(): void
      
      ngAfterContentInit(): void
    
参数

没有参数。

返回值

void

使用说明

下列代码展示了组件如何实现该接口,并定义它自己的内容初始化逻辑。

The following snippet shows how a component can implement this interface to define its own content initialization method.

@Component({selector: 'my-cmp', template: `...`}) class MyComponent implements AfterContentInit { ngAfterContentInit() { // ... } }
      
      @Component({selector: 'my-cmp', template: `...`})
class MyComponent implements AfterContentInit {
  ngAfterContentInit() {
    // ...
  }
}