observable

How to debug Observable values in Angular2 / Typescript?

点点圈 提交于 2019-12-21 05:17:08
问题 I have followed the tutorial for angular 2 and have a search functionality that renders a list of heroes asynchronously. <div *ngFor="let hero of heroes | async"> {{hero.name}} </div> In the component I have observable heroes: heroes: Observable<Hero[]>; Now I have implemented similar functionality in my application by I don't see anything and I don't see any errors either. I opened the debugger in Chrome and tried to check the value of heroes, but it's just some Observable wrapper of course.

angular2: How to use observables to debounce window:resize

狂风中的少年 提交于 2019-12-20 11:48:27
问题 so i am trying to figure out a way to debouce window:resize events using observables, so some kind of function would be called only after user stoped resizing window or some time has passed without size change (say 1sec). https://plnkr.co/edit/cGA97v08rpc7lAgitCOd import {Component} from '@angular/core' @Component({ selector: 'my-app', providers: [], template: ` <div (window:resize)="doSmth($event)"> <h2>Resize window to get number: {{size}}</h2> </div> `, directives: [] }) export class App {

angular2 wait until observable finishes in if condition

廉价感情. 提交于 2019-12-20 11:21:47
问题 I have implemented a if statement like this if (this.service.check() ) { return true; } else { } this if condition waits for a response from the backend. But before the observable gets executed it's going into the else statement and finishing the condition without checking the if condition at start. this is my observable method to get the data from backend public check(){ this.getActorRole().subscribe( (resp => { if (resp == true){ return true } }), (error => { console.log(error); }) ); } }

angular2 wait until observable finishes in if condition

狂风中的少年 提交于 2019-12-20 11:21:39
问题 I have implemented a if statement like this if (this.service.check() ) { return true; } else { } this if condition waits for a response from the backend. But before the observable gets executed it's going into the else statement and finishing the condition without checking the if condition at start. this is my observable method to get the data from backend public check(){ this.getActorRole().subscribe( (resp => { if (resp == true){ return true } }), (error => { console.log(error); }) ); } }

create Observable<T> from result

与世无争的帅哥 提交于 2019-12-20 11:03:15
问题 I am trying Angular2. I noticed that the http service use Observable object instead of Promise (I don't like much that choice.. async / await are arriving). In my service, I download a list of Plants from the webservice. Clicking on a plant I show the details using the routing. But in this way when I go back, the plants are downloaded again (because the constructor is called again). To avoid this I want to do something like: public getPlants(): Observable<Plants[]> { if (this._plants != null)

Fetch data once with Observables in Angular 2

倖福魔咒の 提交于 2019-12-20 10:42:06
问题 I have a service, what is used several times from a lot of my Angular 2 components. It fetches customer data from a Web API and returns an Observable: getCustomers() { return this.http .get(this.baseURI + this.url) .map((r: Response) => { let a = r.json() as Customer[]; return a; }); } I inject this service in my root component, and in every component that wants to access the customers I just subscribe to that Observable: this.customerService.getCustomers().subscribe(v => this.items = v);

Knockoutjs computed passing parameters

淺唱寂寞╮ 提交于 2019-12-20 08:56:54
问题 I am wondering if it is possible with knockoutjs to pass arguments when binding. I am binding a list of checkboxes and would like to bind to a single computed observable in my viewmodel. In my viewmodel (based on parameter passed to the read function) I want to return true/false based on certain conditions. var myViewModel=function(){ this.myprop=ko.computed({read: function(){ //would like to receive an argument here to do my logic and return based on argument. } }); }; <input type="checkbox"

Angular4 Websocket rxjs Reconnect and onError

亡梦爱人 提交于 2019-12-20 06:29:57
问题 It looks like there are several similar questions but after several days I do not find the proper answer. My question is how to know if the server has closed the websocket and how to try to reconnect. I have seen several examples but none of them worked properly when I wanted to implement the fonctionality of closing the websocket from the client when I change the view. Then I found this example which it's the best one I have seen so far, and with a small modifications I was able to add a

Angular Firebase listen to foreach changes with subscribe

爱⌒轻易说出口 提交于 2019-12-20 06:29:56
问题 I am subscribing to get user chats and then for each chat, I am subscribing to two other observables. get_user_chat(chat) { let user = this.firebase.get_user_by_uid(chat.key).snapshotChanges(); let chatInfo = this.firebase.get_single_chat(chat.payload.val()).snapshotChanges(); return Observable.forkJoin(user.take(1), chatInfo.take(1)); } getChats() { //start loading let loading = this.loadingCtrl.create(); loading.present(); //get chats this.firebase.get_user_chats().snapshotChanges()

Angular 7: How to re-write nested subscribtions?

会有一股神秘感。 提交于 2019-12-20 06:12:25
问题 I have a component that displays a filtered list of items. It is subscribed to two observables - the first one is for (filter) parameters that need to be passed into the second observable to get the filtered list of items. public filteredItems = []; this.myService.getFilterParams() .subscribe(params => { this.myService.getFilteredItems(params) .subscribe(items => { this.filteredItems = items}); }); I've read that chaining subscribtion is not the best practice (the code works fine otherwise),