这条规则究竟有什么作用?
"use-life-cycle-interface": true,
最佳答案
它只是意味着你必须为你使用的每个生命周期钩子(Hook)添加 implements 关键字,
虽然这不是 Angular 识别和使用钩子(Hook)所必需的,但对于代码的清晰性和维护性来说要好得多。
例子:
// don't forget the import
import { AfterViewInit } from '@angular/core';
// you have to have this implements statement
export class YourComponent implements AfterViewInit {
// if you want to use this hook
ngAfterViewInit() {
// your code...
}
}
关于angular - 在 Angular 2 中使用生命周期接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38918000/