rxjs - Angular: Observable model property does not exist -


after upgrading angular 2 angular 4 these errors when trying compile using aot:

property 'total' not exist on type 'observable<any>'. 

this how have used observables until now...

first have assigned variable this:

public mydata: observable<any>; 

then have call service subscribe this:

this.mysubscription = this.apiservice.get('url-here')                         .subscribe(                             response => this.mydata = response,                             error => this.feedbackservice.displayerror(<any>error),                             () => this.feedbackservice.stoploading()                         ); 

this works in development mode (ng serve), , can use stuff *ngfor iterate on results.

after getting these errors tried add model class this:

export class mydata {     total: number;     count: number;     data: array<any> = []; } ... rest of component here 

and use observable this:

public mydata: observable<mydata>; 

but still errors when trying compile:

property 'total' not exist on type 'observable<mydata>'. 

what doing wrong?

update:

this service method looka like:

return this.http         .get(apiurl + apipath, {headers: headerswithtoken})         .timeoutwith(appsettings.maxtimehttpcalls, observable.defer(() => observable.throw(this.feedbackservice.timeout())))         .map((response: response) => {             return response.json();         })         .catch((err: response) => {             return err.json();         }); 

all values (including total) exists on returned json , can use in html without problem.

turns out aot doesn't elvis operators in angular 4.

i kept observable<any> on components , wrapped entries containing stuff {{mydata?.total}} inside *ngif check (and removed ?) , errors went away.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -