填寫這份《一分鐘調查》,幫我們(開發組)做得更好!去填寫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
}
    

實現類別

參見

方法

一個回呼(Callback)方法,它會在 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
    
引數

沒有引數。

返回值

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() {
    // ...
  }
}