angular-observable

How does HTTP error-handling work with observables?

大憨熊 提交于 2019-12-20 12:08:31
问题 I see a lot of tutorials doing something like this: http.get("...").subscribe( success => console.log('hello success'), error => console.log('bye error') ); I don't know how this works, since there aren't any types or anything, however I tried to do that myself and I end up that the request always goes into success, even if I have an error. What is the problem? Troublemaker: this.memberService.create(this.currentMember) .subscribe( success => { let mem: Member = success.json() as Member; if

How does HTTP error-handling work with observables?

流过昼夜 提交于 2019-12-20 12:08:17
问题 I see a lot of tutorials doing something like this: http.get("...").subscribe( success => console.log('hello success'), error => console.log('bye error') ); I don't know how this works, since there aren't any types or anything, however I tried to do that myself and I end up that the request always goes into success, even if I have an error. What is the problem? Troublemaker: this.memberService.create(this.currentMember) .subscribe( success => { let mem: Member = success.json() as Member; if

Could not use Observable.of in RxJs 6 and Angular 6

心不动则不痛 提交于 2019-12-17 17:53:23
问题 import { Observable, of } from "rxjs"; // And if I try to return like this return Observable.of(this.purposes); I am getting an error stating, Property 'of' does not exist on type 'typeof Observable' 回答1: Looks like cartant's comment is correct, the RxJS upgrade guide doesn't cover that method specifically but does say "Classes that operate on observables have been replaced by functions" Which seems to mean all or most of those class methods like .of, .throw etc. have been replaced by a

subscribing to observable even when next is not called on BehaviorSubject

北城以北 提交于 2019-12-13 21:08:12
问题 I have a simple scenario: service.ts: private showComposeBoxAction = new BehaviorSubject<boolean>(null); showComposeBox = this.showComposeBoxAction.asObservable(); openComposeBox(event:boolean) { console.log("in openComposeBox"); this.showComposeBoxAction.next(event); } Component.ts: constructor( private _service: Service, ) { this.subscriptions.add( this._mailingService.showComposeBox.subscribe(event => { if (event) { this.displayCompose = true; console.log("showComposeBox displayCompose",

How can I update my subscribe data?

会有一股神秘感。 提交于 2019-12-12 04:33:13
问题 I have a service that makes some http call to a rest api. On my component I have a subscribe to it. How can I update the data on the subscribe without having to make a new call to the service? 回答1: The question is not quite clear, but I think I can infer enough to hopefully offer an answer. Let's assume you have an observable of a User object that has an OrganizationId property on it, and you want an observable of the Organization object associated with that OrganizationId . You want it to

Angular : Dynamically push data to observable without changing value in input

我与影子孤独终老i 提交于 2019-12-11 18:49:08
问题 I have used mat-autocomplete with Angular material 7. this.salesPickerAutoComplete$ = this.autoCompleteControl.valueChanges.pipe( startWith(''), debounceTime(400), distinctUntilChanged(), switchMap(value => { if (value && value.length > 2) { return this.getSalesReps(value); } else { return of(null); } }) ); getSalesReps(value: string): Observable<any[]> { const params = new QueryDto; params.$filter = `substringof('${value}',FirstName) or substringof('${value}',LastName)`; params.$select =

Unable to subscribed data into a variable [duplicate]

耗尽温柔 提交于 2019-12-11 17:42:55
问题 This question already has answers here : How do I return the response from an Observable/http/async call in angular? (8 answers) Closed 2 years ago . I am new in using Observables. So here is my code recipesList:Recipe[]; private recipes; constructor(private shoppingService:ShoppingListService,private http:Http){ this.getRecipesFromUrl().subscribe((data)=>{ this.recipesList=data; console.log(this.recipesList);//printing array containing recipes }); console.log(this.recipesList);//printing

How to wait return statement if subscriber not completed in angular 2/4/6

老子叫甜甜 提交于 2019-12-11 05:30:39
问题 Currently I am working on the Angular6 project, and I have auth-http-interceptor. The problem in this file is that I want to get refresh token/acquire token from angular4-adal service every time, and for that, I have to subscribe the acquire token which will give the token and then want to assign that token in authReq object. But my intercept method's return type is Observable. Then how could I wait for subscribing the acquire token and then return next.handle(authReq). I have tried to write

RxJS how to return Observable with default error handling function

浪子不回头ぞ 提交于 2019-12-11 05:26:43
问题 In my application I have some methods returning an Observable: public myMethodReturningObs(...): Observable { return this.http.get(...); // this will return an Observable } then I call this method in several places around my application: this.service.myMethodReturningObs().subscribe( (data) => { /* do something with data */ }, (error) => { console.log('Error!'); } ); // ... this.service.myMethodReturningObs().subscribe( (data) => { /* do something else with data */ }, (error) => { console.log

Why Angular uses Observable for HttpClient?

落花浮王杯 提交于 2019-12-09 08:47:47
问题 As per https://angular.io/tutorial/toh-pt6 In general, an observable can return multiple values over time. An observable from HttpClient always emits a single value and then completes, never to emit again. Which is indeed true, Http request/response can't produce any more values once the request completes. So what is the main reason HTTPClient returns an Observable while making a request ? Is it simply because we can apply huge set of operators on Observable (retry, debounce and so on) ? or