[英]Generic type Subject<T> requires 1 type argument(s). - Angular
我正在从我的服务中获取数据,我对订阅后取消订阅很重要感到愤怒,我是这样做的:
export class RItemComponent implements OnInit {
apiPath = environment.apiUrl;
private ngUnsubscribe: Subject = new Subject();
constructor(private _sharedService: SharedService) { }
rItems: Product[];
ngOnInit() {
this._sharedService.
getReceiptItem().takeUntil(this.ngUnsubscribe).
subscribe(products => this.rItems = products);
}
ngOnDestroy() {
this.ngUnsubscribe.next();
this.ngUnsubscribe.complete();
}
}
但现在我收到一个错误:
Generic type Subject<T> requires 1 type argument(s). subscribe
我不明白为什么?
任何形式的帮助都会很棒,谢谢!
为主题添加通用类型
private ngUnsubscribe: Subject<any> = new Subject();
Subject
类在 TypeScript 中有一个泛型类型参数。 这意味着,此类的实例只能通过传递额外的类型参数来创建,如下所示:
private ngUnsubscribe: Subject<MyClass> = new Subject();
安装
npm install @types/googlemaps@3.39.12 --save-dev
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.