rxjs

How to wait for guards in Angular

☆樱花仙子☆ 提交于 2019-12-18 04:53:19
问题 If i specify three guards on a route, it seems as though all guards are evaluated immediately. {path: '', component: OptionsComponent, canActivate: [ GuardOne, GuardTwo, GuardThree]} The problem I have is I don't want GuardTwo to run until GuardOne has finished. Is there any way to achieve this? 回答1: I don't think that's possible in the 4.1.3. Here is the code that runs the guards: private runCanActivate(future: ActivatedRouteSnapshot): Observable<boolean> { const canActivate = future.

Angular 2 new Router: How to get router parameters of a child component?

二次信任 提交于 2019-12-18 04:39:14
问题 In the latest version of @angular/router 3.0.0-rc.1 The way you get the parameters from a URL/route changed. Based on this documentation you should be able to get the params by subscribing to the params but in my case it seems that is not working. What I want to achieve is to get params into my parent component FROM child routes. For example let's say this is my routes: const routes: Routes = [ { path: 'parent', component: ParentComponent, pathMatch: 'prefix', children: [ { path: ':id',

Access variables declared a component from a RxJS subscribe() function

天大地大妈咪最大 提交于 2019-12-18 04:39:11
问题 I am able to use this.variable to access variables in any part of the component, except inside RxJS functions like subscribe() or catch() . In the example below, I want to print a message after running a process: import {Component, View} from 'angular2/core'; @Component({ selector: 'navigator' }) @View({ template: './app.component.html', styles: ['./app.component.css'] }) export class AppComponent { message: string; constructor() { this.message = 'success'; } doSomething() { runTheProcess()

Missing observable methods RxJS 5.0.0-beta.0

主宰稳场 提交于 2019-12-18 04:38:17
问题 I'm having a problem using RxJS with Angular 2. Most of methods suggested from Typescript definition file are not defined on my Observable object like... then I figured out, that methods does not exists on the Observable prototype. I know a lot of things changed from version 4 to 5,so do I miss something? Browserify added it for me... 回答1: Without seeing your actual code, I can't tell you exactly what to add to fix it. But the general problem is this: RxJS 5 is not included with Angular 2 any

Rxjs, understanding defer

倾然丶 夕夏残阳落幕 提交于 2019-12-18 04:37:11
问题 I searched for usage defer in Reactive, but still I don't understand why and when use the defer method. As I understand all Observable method will not be fired until it subscribed, then, why we need to wrap the observable method with defer method? Please advice me, and would be very appreciated if giving me with example. [Updated] Now I understood. In reactive documentation, I saw this example, var source = Rx.Observable.defer(function () { return Rx.Observable.return(42); }); var

How use async service into angular httpClient interceptor

前提是你 提交于 2019-12-18 04:12:24
问题 Using Angular 4.3.1 and HttpClient, I need to modify the request and response by async service into the HttpInterceptor of httpClient, Example for modifying the request: export class UseAsyncServiceInterceptor implements HttpInterceptor { constructor( private asyncService: AsyncService) { } intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { // input request of applyLogic, output is async elaboration on request this.asyncService.applyLogic(req).subscribe(

Pattern for shareReplay(1) in RxJS5

我是研究僧i 提交于 2019-12-18 03:25:11
问题 I've started playing with RxJS5, and now see that there is no longer a shareReplay method. It's quite possible that I often misused shareReplay in RxJS4, but now I'm struggling to get the behaviour that I want, i.e: Create an observable Subscribe to the observable, and the observable produces a value Subscribe to the observable a second time, and I get the same first value Observable produces a second value, and both subscriptions get the second value How do I implement this with RxJS5? In

“async” pipe not rendering the stream updates

一世执手 提交于 2019-12-18 03:17:08
问题 Trying to render the window size on window resize through a stream in an angular 2 component utilizing an async pipe: <h2>Size: {{size$ | async | json}}</h2> const windowSize$ = new BehaviorSubject(getWindowSize()); Observable.fromEvent(window, 'resize') .map(getWindowSize) .subscribe(windowSize$); function getWindowSize() { return { height: window.innerHeight, width: window.innerWidth }; } @Component({ selector: 'my-app', providers: [], template: ` <div> <h2>Size: {{size$ | async | json}}<

rxjs 5 publishReplay refCount

岁酱吖の 提交于 2019-12-18 03:08:16
问题 I can't figure out how publishReplay().refCount() works. For example (https://jsfiddle.net/7o3a45L1/): var source = Rx.Observable.create(observer => { console.log("call"); // expensive http request observer.next(5); }).publishReplay().refCount(); subscription1 = source.subscribe({next: (v) => console.log('observerA: ' + v)}); subscription1.unsubscribe(); console.log(""); subscription2 = source.subscribe({next: (v) => console.log('observerB: ' + v)}); subscription2.unsubscribe(); console.log("

Angular 4 - “Expression has changed after it was checked” error while using NG-IF

£可爱£侵袭症+ 提交于 2019-12-18 02:40:11
问题 I setup a service to keep track of logged in users. That service returns an Observable and all components that subscribe to it are notified (so far only a single component subscribe to it) . Service: private subject = new Subject<any>(); sendMessage(message: boolean) { this.subject.next( message ); } getMessage(): Observable<any> { return this.subject.asObservable(); } Root App Component: (this component subscribes to the observable) ngAfterViewInit(){ this.subscription = this._authService