![](/img/trans.png)
[英]How do I implement OnInit without getting error: Class is using Angular features but is not decorated. Please add an explicit Angular decorator
[英]Angular 8+ - do I need to implement the OnInit function in my components if I am not planning to override it?
我正在使用 Angular 8 進行項目。
我注意到,當我使用 OnInit 附帶的命令行生成組件時。
例如
export class SideDrawerComponent implements OnInit {
constructor(private sideDrawerService: SideDrawerService) { }
public ngOnInit(): void { }
public close() {
this.sideDrawerService.closeDrawer();
}
}
由於我不會覆蓋 function,我需要它嗎?
不,您可以刪除它和 OnInit 接口。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.