observable

'of' from Observables

和自甴很熟 提交于 2019-12-13 20:18:32
问题 I was doing this tutorial on reactive forms and stumbled on following problem: import { Observable, of } from 'rxjs'; here you should import of from rxjs but when I try to it say's: [ts] Module '"/.../node_modules/rxjs/Rx"' has no exported member 'of'. Also tried import 'rxjs/add/observable/of'; which didn't work either. In the example 'of' is used for following: getHeroes(): Observable<Hero[]> { return of(heroes).pipe(delay(this.delayMs)); // simulate latency with delay } Any suggestions how

Catch in Observable stops HTTP Calls from Observable.interval

Deadly 提交于 2019-12-13 16:36:01
问题 Observable.interval(10000) .switchMap(() => this.http.get(url)) .catch (err => Observable.empty()) .subscribe(data => render(data)) Each 10 seconds we make an HTTP call. If an error happens, observable becomes completed, it doesn't make any calls anymore. How to prevent that? 回答1: That's correct behavior, when a complete or error notification is sent observers unsubscribe and the chain is disposed. You can use the retry() operator to resubscribe but it's hard to tell what is your goal from

Async Pipe Fails to Render Observable

无人久伴 提交于 2019-12-13 16:34:54
问题 e(1): Updated code to address typo's in original question. e(2): Attempted to 'JSON.stringify()' the data pushed into my JSON object in 'createContent()'. No luck. e(3): Added plnkr as requested: http://plnkr.co/edit/j024MYCQbypAGaf762fT I have a model... class Content { constructor(public name: string) { } } I have a service... class ContentService { private _contents$: Subject<Content[]> = new Subject<Content[]>(); get contents$(): Observable<Content[]> { return this._contents$.asObservable

Execute http request sequentially in Angular 6

假装没事ソ 提交于 2019-12-13 16:25:06
问题 I need to send multiple HTTP PUT request to server sequentially (after the next request is only started after completing the previous request, the number of request is not fixed). If I use the below source code, all request will be sent `listURL.forEach(url => { const req = new HttpRequest('PUT', url, formData, { reportProgress: true}); httpClient.request(req).subscribe(event=>{}); });` Is there anyway to execute the requests sequentially? 回答1: If you are not familiar with rxjs, perhaps you

RXJS - Angular - unsubscribe from Subjects

僤鯓⒐⒋嵵緔 提交于 2019-12-13 13:22:40
问题 As described in this thread, 'official' solution to unsubscribe from Observables in Angular 5+ in general is using takeUntil. So far, so good. My question is, does this also apply if the Observable I am subscribed to is actually a Subject? 回答1: Once you call .subscribe() on anything (Subjects too), something needs to make sure the subscription gets unsubscribed. Dealing with finite Observables : If you subscribe to a finite observable (meaning an observable that has a finite/limited sequence)

ng2-translate customLoader & multiple files per language

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 12:42:41
问题 In an Ionic2 app I'm using ng2-translate the strings in my app. Now I need to split the translation file into several files per language, for example "de.json" and "de_gs1ais.json". As ng2-translate is limited to one file per language I've tried to implement a custom loader: class CustomLoader implements TranslateLoader { private http: Http; public getTranslation(lang: String): Observable<any> { return this.http.get("assets/i18n" + "/" + lang + ".json").map((res) => res.json()); } } This

When to use Promise over observable?

纵饮孤独 提交于 2019-12-13 12:04:17
问题 Is there any case, where Promise is more powerful as compare to observable? I know a lot of benefits of observables over promises. But Is there any case, I should use only promises over observables. I found this link, promises vs observables. But this always shows me the benefits of observables over promises. I want to know the benefits of promise over observables. 回答1: An observable does everything that a promise does and more. It can always be switched to a promise with toPromise() method

HTTP call using Observable not working

为君一笑 提交于 2019-12-13 10:11:21
问题 In the function below, I have two calls to the server, one using Observable and the other using Promise. The call using Observable does not reach the server but the one using promise does. Any idea why? public placeOrder(order:string) { //Using Observable this.http.post(this.newOrderUrl, {order: order}, this.options) .map((response:Response) => { console.log('new order', response.json()) }) //Using Promise this.http.post(this.newOrderUrl, {order: order}, this.options) .toPromise() .then(

Guarantee observable subscription finishes before proceeding to next code

非 Y 不嫁゛ 提交于 2019-12-13 09:07:08
问题 I am doing a bit of a cascade delete with multiple service calls. Some of the later subscriptions rely on previous subscriptions to finish. How can I guarantee an subscription finishes before moving onto my next code? // Need to make sure this code completes data.forEach(element => { this.myService.delete(element.id).subscribe(); }); // Before running this code this.myService.getAll().subscribe(res => { res.data.forEach(element => { this.myService.delete(element.id).subscribe(); }); } ); 回答1:

After getting the response from post api call , an error is thrown => .pipe is not a function

只愿长相守 提交于 2019-12-13 07:57:29
问题 I am making an api call and expecting a response from it which can be passed to 2nd api call but I am getting an error ERROR TypeError: this.helperService.getPointIdbyTags(...)[0].pipe is not a function on line .pipe(switchMap((resarray:any)=>{ TS code someFunction(floor){ floor.entities.forEach(element => { let desiredTempForZone; this.getCurrentValue(element.name).subscribe((des) => { currentTempForZone = des }); console.log(currentTempForZone); }) } getCurrentValue(eleName){ let roomObj =