behaviorsubject

Is it possible to pass data after initializing the components?

北慕城南 提交于 2021-02-20 02:36:27
问题 I have three components as shown on the image below and use a custom form component in my feature component. However, there is not a direct parent-child relationship between these two components and there is also a form component between them. I pass data from feature to form using @Input propert that has input values inside a config data (let's say "configData") and then pass them to custom component via @Input property (let's say "configData.test" for test input) without any problem (I can

Cannot get and set value to BehaviorSubject in angular

杀马特。学长 韩版系。学妹 提交于 2021-02-08 11:51:26
问题 I'm trying to add a boolean value to a BehaviorSubject. However, when I try to console log it says that it is undefined. What I'm doing wrong? This is how I declare it. isDesktopWidth: BehaviorSubject<boolean>; And this is how I use it changeSideBarWidth() { if (this.innerWidth > 767) { this.isDesktopWidth.next(true); } else { this.isDesktopWidth.next(false); } } And then in the ngOnInit this.changeSideBarWidth(); console.log(this.isDesktopWidth.value); But it doesn't display anything in the

Behaviour subject value is empty when trying to fetch from a second component

烂漫一生 提交于 2021-01-29 11:01:59
问题 I am trying to share data between two components in Angular 8 using BehaviourSubject and a shared service. The code in component 1 is shown below. constructor(private appSharedService: AppSharedService) { } ngOnInit() { this.appSharedService.getCars() .subscribe(response => { this.cars = response; this.appSharedService.updateCarsList(this.cars); }, error => { console.log(error); }); } The code in the shared app-shared service is export class AppSharedService { carsSubject : BehaviorSubject

Add elements to rxjs BehaviorSubject or Subject of an array in Angular2+

无人久伴 提交于 2021-01-28 08:11:52
问题 I was reading up on how to share data between unrelated components in Angular from the "Unrelated Components: Sharing Data with a Service" section of the tutorial here. I see how this example works for the string they are trying to share across their components, but my data type is a little more complex: Namely, I think my BehaviorSubject should look like this: private currentPopulationSource: BehaviorSubject<Population> = new BehaviorSubject<Population>(new Population(new Array<Organism>()))

Sharing Data between Components (Angular 7)

↘锁芯ラ 提交于 2020-12-11 04:42:27
问题 I am currently trying to send data between components via a data service using "BehaviorSubject". In the first component, I am updating the messageSoruce and in the second component , retrieving the data but it is empty. I checked that the value "this.card.img" is not empty. What am I missing ? Data Service import { Injectable } from '@angular/core'; import { BehaviorSubject, Subject } from 'rxjs'; @Injectable() export class DataService { private messageSource = new BehaviorSubject("")

Sharing Data between Components (Angular 7)

对着背影说爱祢 提交于 2020-12-11 04:40:48
问题 I am currently trying to send data between components via a data service using "BehaviorSubject". In the first component, I am updating the messageSoruce and in the second component , retrieving the data but it is empty. I checked that the value "this.card.img" is not empty. What am I missing ? Data Service import { Injectable } from '@angular/core'; import { BehaviorSubject, Subject } from 'rxjs'; @Injectable() export class DataService { private messageSource = new BehaviorSubject("")

Why RXJS angular behaviorSubject emit mutiple values

允我心安 提交于 2020-07-22 06:28:08
问题 enter image description hereI use BehaviorSubject to share data between my app components, I have a performance issue due to mutiple emission of same value from BehaviorSubject . For instance, I call http to get team Object from backend and store it in a behaviorSubject, many components subscribe to this BehaviorSubject . Each component gets the value from subscription and does a sequence of manipulations on the value. The essence of the problem is that the value is emitted many times and

How to use Ionic Data Storage with BehaviorSubject and Observable

≡放荡痞女 提交于 2020-06-17 15:26:26
问题 I'm trying to create app with Angular 9 / Ionic 5 I'm using Ionic Data Storage So, my auth.service.ts looks like: import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Storage } from '@ionic/storage' import { BehaviorSubject, Observable, from } from 'rxjs' @Injectable({ providedIn: 'root' }) export class AuthService { private currentTokenSubject: BehaviorSubject<string> public currentToken: Observable<string> constructor( private

How to implement behavior subject using service in Angular 8

眉间皱痕 提交于 2020-05-27 05:40:10
问题 I'm new to Angular and I'm having an issue. I'm creating an app with several sibling components. When I update a value in one component other components don't update. I know that to resolve this issue I should use behaviour subject . But how do I implement it with my service, the components and all the templates? Here is my code - ---------------------- My service --------------------------- //import @Injectable() export class CoachService { apiURL = environment.apiURL; constructor(private

How to use BehaviourSubjects to share data from API call between components in Angular?

蓝咒 提交于 2020-04-07 08:09:06
问题 I am currently building an Angular application where I make a request to an api, and I map the repsonse to two different arrays. I can use this data in my app.components.ts but I will make new components for what I need. How can I share the data between components to ensure that the components always have the latest data because I will also need to periodically call the API. I've seen some answers on SO and some youtube videos but I'm just not fully understanding it. The code of my service is