behaviorsubject

full calendar - passing event data from observable - not showing up on calendar

回眸只為那壹抹淺笑 提交于 2020-01-06 08:33:49
问题 I am using ap-fullcalendar for angular/typescript. I have a data service, where I get the events for the calendar from my database, I wrap the data in a Behaviour Subject and subscribe to it and make it into an observable from another function. I have a data service because I have multiple subscriptions to the same observable. In my component where the calendar is, I subscribe to the data. However, for some reason, the events are not getting passed properly to the calendar and won't show up.

BehaviorSubject subscriber gets same next() element multiple times

狂风中的少年 提交于 2019-12-25 02:15:36
问题 I'm using a shareData service using BehaviorSubject like the one below. My problem is that every time I call the service's changeMessage method from one component the listener messageSource subscription in any other component is called several times, looks like it received the same message several times. Is this expected behavior? How to prevent it? The service is a singleton. I do not call changeMessage multiple times @Injectable() export class ShareDataService { messageSource = new

Loop For on a BehaviorSubject stream

泪湿孤枕 提交于 2019-12-24 19:17:44
问题 My thread variable contains 3 different elements. I want to create a For loop that iterates on these three objects. threads: BehaviorSubject<{[key: string]: Thread }> = new BehaviorSubject({}); Here is my function: searchUser(): Observable<Thread> { this.searchArrayThreads = []; let element = document.getElementById('chat-window-input'); return this.threads.map((threadDictionary: {[key: string]: Thread}) => { for( let key in threadDictionary ) { console.log("key", threadDictionary[key]); if

Unit test: Mocking service that returns observables to return subjects in order to test change of values over time causes TS to throw TS2339

三世轮回 提交于 2019-12-23 19:44:59
问题 I have a service that returns the values exposed by ngrx selectors, and a component that defines this service, injects it and sets properties based on the values returned by the service. I am writing unit tests for the component using a mock of the service, and I need the mock service to return different values for each unit test. In order to do this I have defined the mock service class so it returns subjects instead of observables. The tests run, but TS throws an error saying that the

observable subscription does not work when written in ngOnit() in IE

巧了我就是萌 提交于 2019-12-23 11:46:22
问题 I have defined a behavior subject: component.ts bsub1: BehaviorSubject<Array<any>> = new BehaviorSubject(null); And called next() on it: html: <button (click) = getData()>Data</button> component.ts: getData() { getSomething(value, bsub1); } service.ts getSomething(value, _observable) { //do something _observable.next(retun) somevariable.map(p => { return { "a": value1, "b": value2 } }); } And made a subscription: component.ts ngOnInit() { bsub1.subscribe(list=>{ console.log("subscribed to

observable subscription does not work when written in ngOnit() in IE

落花浮王杯 提交于 2019-12-23 11:46:14
问题 I have defined a behavior subject: component.ts bsub1: BehaviorSubject<Array<any>> = new BehaviorSubject(null); And called next() on it: html: <button (click) = getData()>Data</button> component.ts: getData() { getSomething(value, bsub1); } service.ts getSomething(value, _observable) { //do something _observable.next(retun) somevariable.map(p => { return { "a": value1, "b": value2 } }); } And made a subscription: component.ts ngOnInit() { bsub1.subscribe(list=>{ console.log("subscribed to

How to convert an Observable into a BehaviorSubject?

久未见 提交于 2019-12-23 07:41:29
问题 I'm trying to convert an Observable into a BehaviorSubject. Like this: a$ = new Observable() b$ = BehaviorSubject.create(new BehaviorSubject(123), a$) // 🔴 I have also tried: a$ = new Observable() b$ = new BehaviorSubject(a$, 123) // 🔴 And: a$ = new Observable() b$ = a$.asBehaviorSubject(123) // 🔴 And: a$ = new Observable() b$ = a$.pipe( toBehaviorSubject(123) ) // 🔴 But none of these works. For now I have to implement like this: a$ = new Observable() b$ = new BehaviorSubject(123) a$

RxJs BehaviorSubject's next() method in service

心已入冬 提交于 2019-12-23 06:07:56
问题 I use the following approach in order to refresh Details page after a new record added. I also need to refresh after updating a record as well. EventProxyService export class EventProxyService { private eventTracker = new BehaviorSubject<any>(); getEvent(): Observable<any> { return this.eventTracker.asObservable(); } setEvent(param: any): void { this.eventTracker.next(param); } } CreateComponent: export class CreateComponent implements OnInit { constructor(private eventProxyService:

How to implement nested secondary routing and still get the data from child? Angular 6

白昼怎懂夜的黑 提交于 2019-12-20 04:53:34
问题 My goal is to send data from a routed child to the parent. I want to get the reference of a variable from the child, which is nested within a child to the parent through secondary routes so that the variable is synced to the parent. This variable will eventually be the boolean of a form validation state. Unfortunately, when I use Behavior Subject I think I have to use the component selector which seems not to play nicely with the routes in my application. This is a sample from the template of

BehaviorSubject is executed more than once

不羁岁月 提交于 2019-12-20 04:50:30
问题 I am using angular 4 for my app and I use behaviorSubject to communicate between component, everythings were working fine Here is my code: export class Globals { loadStudentsByClass: BehaviorSubject<string> = new BehaviorSubject<string>(null); } export class ClassComponent implements OnInit { selectNewClass() { console.log('About to select new class', this.selectedClass); this.globals.loadStudentsByClass.next(this.selectedClass); this.globals.changeClassBehavior.next(true); this.router