简体   繁体   中英

How to push the empty JSON data to an array field which is type of Observable<any[]> angular 2

I have a variable like,

public categories: Observable<any[]>;

So after the service call, the returned data of service call will push an array of JSON data to the field which I mentioned above.

After that, I need to push an empty JSON data to that field. As it is a type of Observable, I can't just directly use .push

Is there any solution to push the empty JSON data to an array which is type of Observable?

You just need to import latest EmptyObservable of rxjs , that will do the trick in your case.

import {EmptyObservable} from 'rxjs/observable/EmptyObservable';

public categories: Observable<any[]>;

//just assign this to your variable
this.categories = new EmptyObservable();

for more info have a look here

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM