Within my code, I am invoking this operation in the ngOnInit function to ensure that previously edited data can be viewed when the page is reopened. The property StickerData
belongs to the interface IStickerData. However, I keep encountering an error:
ERROR TypeError: Cannot set property 'StickerData' of undefined
at SafeSubscriber._next (sticker-preview.component.ts:54)
at SafeSubscriber.__tryOrUnsub (Subscriber.js:183)
at SafeSubscriber.next (Subscriber.js:122)
at Subscriber._next (Subscriber.js:72)
at Subscriber.next (Subscriber.js:49)
at FinallySubscriber._next (Subscriber.js:72)
at FinallySubscriber.next (Subscriber.js:49)
at CatchSubscriber._next (Subscriber.js:72)
at CatchSubscriber.next (Subscriber.js:49)
at MapSubscriber._next (map.js:35)
This error occurs on
subscribe((response: any) => this._stickerData.StickerData = response);
when the page is opened. What could possibly be missing here?
TypeScript snippet:
private _stickerData: IStickerData;
Filter: IFilter;
@Input()
set StickerData(prm: IStickerData) {
if (this._stickerData != prm) {
this._stickerData = prm;
}
}
get StickerData(): IStickerData {
return this._stickerData;
}
ngOnInit() {
this._productionService.getStickerDataList(this.Filter)
.subscribe((response: any) => this._stickerData.StickerData = response);
}
Service TypeScript code:
getStickerDataList(data: IFilter): Observable<IStickerData[]> {
return this._http.post("Production/GetStickerDataList", data);
}