angular2-observables

Angular 4: Update template variable after API call [duplicate]

怎甘沉沦 提交于 2019-12-20 04:45:12
问题 This question already has answers here : Angular 2 View will not update after variable change in subscribe (4 answers) Closed last year . I have a Component-directive that I use to show a div with some information. This component is called SitesComponent and is included in a page. The main behavior of the SitesComponent is fine, except for this: I have an API call to a backend where I return some data, the backend call is executed well and I received the information but the variable is not

Angular 2: Observable / Subscription not triggering

五迷三道 提交于 2019-12-18 14:16:48
问题 I have done this multiple times in my App. It's simple, it should work... But this time it doesn't. My issue: I am calling a method in a service from a Component A, my Component B is subscribed but doesn't react nor receive anything. subscribe() is not triggering! navigation-elements.service.ts @Injectable() export class NavigationElementsService { updateIBOsNavigation$: Observable<any>; private updateIBOsNavigationSubject = new Subject<any>(); constructor() { this.updateIBOsNavigation$ =

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(

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",

Observable do not receive the next value in angular2

こ雲淡風輕ζ 提交于 2019-12-13 06:26:31
问题 In order to pass value between angular2 different components, I use different services injected into different components. In my PagesService component, I define a behavior subject and want to pass a value. import { Injectable } from '@angular/core'; import { ApiService } from '../../apiService/api.service'; import { Playlists } from '../shared/playlists.model'; import { Subject, BehaviorSubject } from 'rxjs/Rx'; @Injectable() export class PagesService { private currentPlaylists: Subject

Using observable talk to other component in angular2, not receiving coming value

非 Y 不嫁゛ 提交于 2019-12-13 05:25:58
问题 I have this structor app/ --pages/ ----pages.component.ts --channel/ ----shared/ ------assignPlaylist.modal.ts Inside the pages.component.ts, I have a variable called playlist export class PagesComponent { @Input() platform: Platform; @Output() onPlaylistsChange: EventEmitter<Playlists>; currentPageName: string; currentPage: Page; pages: Array<Page>; playlists: Playlists; } In assignPlaylist.modal.ts, I make an http post method and it returns a new playlists, I need to use that returned

Angular rxjs Observable.interval() not triggering properly on background tabs in Chrome

柔情痞子 提交于 2019-12-12 15:35:58
问题 I am writing angular2 application with interval timers implemented via RxJs observables, and just noticed the strange behaviour of Observable.interval() and Observable.timer() in Chrome browser when tab is in background. Angular component should once every second print number of seconds in console, but on background tabs, this is not working as intended - function triggers every x+1 seconds, where x is interval specified explicitely in the interval funciton Angular component code: ngOnInit()

angular2 is it possible to share observable data with other components?

こ雲淡風輕ζ 提交于 2019-12-12 05:14:19
问题 I have a service that GETS a user via a RESTful api. It uses the Observable implementation. I also have a parent component with 8 child components. I want to know if and how I can make a single HTTP request in the parent component, to get the user and share it amongst its children components. Here's the call to define user in the parent: this.userApi.getUser(id) .subscribe(response => {this.user = response;}, error => error); I've imported and injected the user model into the constructor() of

Can't use concatMap() with angular2 Http

耗尽温柔 提交于 2019-12-12 05:12:36
问题 I need to chain many http requests, the number of request is variable and they are not dependant from the result of the previous one, I just need to keep the returned object of the last request. I've been given two solutions on this thread, the first solution using Observable.concat() works, but a contributor suggested me a more elegant way to perform that, by using concatMap() . Here's my current code : MyComponent submitForms() { var formToSubmit = [...]; // Contains dirty forms that be

Communication between multiple components with a service by using Observable and Subject in Angular 2

你。 提交于 2019-12-12 04:45:38
问题 I am new to rxjs, so I would like to ask a question regarding Angular 2 , Observables and BehaviorSubject/Subject . So, what I want to achieve is : onclick of a button inside a ComponentA to notify other components for example ComponentB , ComponentC . What I did so far is to create a service : private isMenuOpenBS = new BehaviorSubject(false); toggleMenu(): void { this.isMenuOpenBS.next(!this.isMenuOpenBS.getValue()); } getMenuState(): Observable<boolean> { return this.isMenuOpenBS