angular-observable

Angular: converting a json get response to class with functions

风流意气都作罢 提交于 2019-12-08 07:19:01
问题 So basically I have an Angular component that has a variable of type DashboardConfiguration that is being set to an Observable. This observable comes from a resolver that calls a service that makes a get request for the json object. The problem is that the observable is feeding the variable a plain Object, and not a DashboardConfiguration object. This is preventing me from calling a function of DashboardConfiguration. I have structured this to be very similar to this example which has all

Execute Multiple Asynchronous Route Guards in Order

▼魔方 西西 提交于 2019-12-07 16:42:52
问题 I know angular route guards execute in the specified order when the canActivate function returns a simple boolean , however, what if the guards return type Observable<boolean> or Promise<boolean> ? Example in route: { path: 'confirm', canActivate: [AuthGuard, SessionExpiredAuthGuard, CheckoutAuthGuard], component: CheckoutReviewOrderComponent }, SessionExpiredAuthGuard and CheckoutAuthGuard both return type Observable<boolean> . I don't want the CheckoutAuthGuard to be executed before the

Angular - Combine params and queryParams observables

我只是一个虾纸丫 提交于 2019-12-06 08:22:33
问题 How can I combine these to observables into one? They have the same functionality. this.sub = this.route.params.subscribe((params: any) => { // functionality }); this.sub = this.route.queryParams.subscribe((params: any) => { // same functionality }); 回答1: You can use combineLatest to do that: import { ActivatedRoute } from '@angular/router'; import { combineLatest } from 'rxjs'; // ... class MyComponent { constructor(private route: ActivatedRoute) { } ngOnInit() { const params = this.route

Execute Multiple Asynchronous Route Guards in Order

耗尽温柔 提交于 2019-12-05 21:02:17
I know angular route guards execute in the specified order when the canActivate function returns a simple boolean , however, what if the guards return type Observable<boolean> or Promise<boolean> ? Example in route: { path: 'confirm', canActivate: [AuthGuard, SessionExpiredAuthGuard, CheckoutAuthGuard], component: CheckoutReviewOrderComponent }, SessionExpiredAuthGuard and CheckoutAuthGuard both return type Observable<boolean> . I don't want the CheckoutAuthGuard to be executed before the SessionExpiredAuthGuard is finished retrieving it's data from the asynchronous http request. Is there any

Angular - Combine params and queryParams observables

对着背影说爱祢 提交于 2019-12-04 12:13:16
How can I combine these to observables into one? They have the same functionality. this.sub = this.route.params.subscribe((params: any) => { // functionality }); this.sub = this.route.queryParams.subscribe((params: any) => { // same functionality }); JayChase You can use combineLatest to do that: import { ActivatedRoute } from '@angular/router'; import { combineLatest } from 'rxjs'; // ... class MyComponent { constructor(private route: ActivatedRoute) { } ngOnInit() { const params = this.route.params; const queryParams = this.route.queryParams; combineLatest(params, queryParams, (params,

Angular 5 - Observable return error cannot read property of undefined

空扰寡人 提交于 2019-12-04 06:20:11
问题 I'm starting to implement a simple pagination using Spring Rest and Angular 5 inside my angular service when I call my web service using httpClient a get a correct response with the requested page it's display data on my page correctly but there an error the console web browser that there an error inside my *ngFor loop cannot read property of undefined although that the template display results correctly : The problem is in the Service method : getPageClient() and the *ngFor directive This

Angular5 HttpInterceptor depending on the result of an Observable

岁酱吖の 提交于 2019-12-03 20:56:17
问题 I am trying to implement using Angular5 an HttpInterceptor to inject an Authorization header in all HTTP requests. I rely on a third party library (ADAL, here called AuthService ) that exposes a acquireToken() method to get the token to be used for Bearer authorization. The problem is that aquireToken() returns an observable, and i have to subscribe to get the real string I need. Therefore, my code never injects the header, i suppose because next.handle() is executed before acquireToken()

Why Angular uses Observable for HttpClient?

久未见 提交于 2019-12-03 11:06:36
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 Is there any other specific reason I am missing ? The best answer you'll find is Pascal Precth 's one

Detect Click outside element in angular 4 using directives

混江龙づ霸主 提交于 2019-12-03 08:39:36
问题 I have used a custom directive to detect click outside an element in angular 2 but the same is not possible in angular 4. [plunkr] https://plnkr.co/edit/aKcZVQ?p=info When I try using the same code in angular-4 I get the following errors: 1. Argument of type '{ template: string; directives: typeof ClickOutside[]; }' is not assignable to parameter of type 'Component'. ==> @Component({ templateUrl: "", directives: [ClickOutside] }) 2. Type 'Subscription' is not assignable to type 'Observable

Detect Click outside element in angular 4 using directives

那年仲夏 提交于 2019-12-03 00:09:24
I have used a custom directive to detect click outside an element in angular 2 but the same is not possible in angular 4. [plunkr] https://plnkr.co/edit/aKcZVQ?p=info When I try using the same code in angular-4 I get the following errors: 1. Argument of type '{ template: string; directives: typeof ClickOutside[]; }' is not assignable to parameter of type 'Component'. ==> @Component({ templateUrl: "", directives: [ClickOutside] }) 2. Type 'Subscription' is not assignable to type 'Observable<MouseEvent>'. in the directive inside ngOnInit() and ngOnDestroy() ngOnInit() { this.globalClick =