angular - 在 Angular 2 中使用生命周期接口(interface)

标签 angular typescript tslint

这条规则究竟有什么作用?

"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/

相关文章:

Angular 2 + ngrx/商店 : one-way binding to an <input>

javascript - Angular7 中的预选下拉菜单

javascript - 无法绑定(bind)到 'property',因为它不是 'selector' 的已知属性

javascript - 使用 facebook 登录让 typescript 为 Angular 2 项目工作

Typescript 测试绝对导入检查问题

javascript - 这可能是关于什么的? [TsLint 错误 : "Promises must be handled appropriately"]

angular - 如何使用按钮样式在 Ionic 2+ 中创建自定义文件输入?

javascript - Nuxt.js 模块中未定义 process.server

javascript - 当我将对象传递给 JavaScript 函数时,该对象是否通过引用传递?

reactjs - 在 typescript 中启用react-hooks eslint插件。 tslint 中没有插件