组件或指令属性已初始化时触发。
(在子指令之前)
import { Component, OnInit } from '@angular/core'; @Component({ selector: 'so-oninit-component', templateUrl: 'oninit-component.html', styleUrls: ['oninit-component.'] }) class OnInitComponent implements OnInit { ngOnInit(): void { console.log('Component is ready !'); } }