gpt4 book ai didi

Angular 2+ 组件很好地扩展了组件,但是 tslint 提示继承的生命周期钩子(Hook)

转载 作者:行者123 更新时间:2023-12-03 22:18:13 25 4
gpt4 key购买 nike

我有一个抽象的基础组件,可以自己清理订阅:

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(){}
}


现在我创建工作组件:

export class CategorySelectorComponent extends NeatComponent {

public constructor() { super(); }

public ngOnInit() {
// some code
}
}


一切正常,但 tsLint 不喜欢我的 ngOnInit 方法:

[tslint] Implement lifecycle hook interface OnInit for method ngOnInit in class CategorySelectorComponent (use-life-cycle-interface)

最佳答案

我认为你可以通过制作来覆盖它

从 :

"use-life-cycle-interface": true,

到 :
"use-life-cycle-interface": false,

更多测试用例详情, Check this out

关于Angular 2+ 组件很好地扩展了组件,但是 tslint 提示继承的生命周期钩子(Hook),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48664690/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com