我有一个抽象的基本组件,可以自己清理订阅:
import { OnDestroy, OnInit } from '@angular/core';
import { Subject } from 'rxjs/Subject';
export abstract class NeatComponent implements OnDestroy, OnInit {
// Add '.takeUntil(this.ngUnsubscribe)' before every '.subscrybe(...)'
// and this subscriptions will be cleaned up on component destroy.
protected ngUnsubscribe: Subject<any> = new Subject();
public ngOnDestroy() {
this.ngUnsubscribe.next();
this.ngUnsubscribe.complete();
}
public ngOnInit(){}
}Run Code Online (Sandbox Code Playgroud)
现在我创建工作组件:
export class CategorySelectorComponent extends NeatComponent {
public constructor() { super(); }
public ngOnInit() {
// some code
}
}Run Code Online (Sandbox Code Playgroud)
一切正常,但 tsLint 不喜欢我的 ngOnInit 方法:
[tslint] 为 CategorySelectorComponent 类中的 ngOnInit 方法实现生命周期钩子接口 OnInit(使用生命周期接口)
我认为你可以通过以下方式覆盖这个
从 :
"use-life-cycle-interface": true,
Run Code Online (Sandbox Code Playgroud)
到 :
"use-life-cycle-interface": false,
Run Code Online (Sandbox Code Playgroud)
有关测试用例的更多详细信息,请查看此
| 归档时间: |
|
| 查看次数: |
1387 次 |
| 最近记录: |