I'm getting data from my service and I've red about it's important to unsubscribe after subscribe, and here is how I did it:
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();
}
}
But now I'm getting an error:
Generic type Subject<T> requires 1 type argument(s). subscribe
I don't understand why?
Any kind of help would be awesome, thanks!
为主题添加通用类型
private ngUnsubscribe: Subject<any> = new Subject();
The Subject
class has a generic type parameter in TypeScript. This means, that instances of this class can only be created by passing an additional type parameter, like this:
private ngUnsubscribe: Subject<MyClass> = new Subject();
安装
npm install @types/googlemaps@3.39.12 --save-dev
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.