subject-observer

Angular communication between two components using subject

筅森魡賤 提交于 2020-08-10 19:17:47
问题 I have two angular components and need to pass in an object from one component to another on a click. My first component has the following showEventDetails(event: Event) { this.eventsService.sendEventDetail(event) } Here Event is my custom model object: export class Event { id: number title: string description: string url: string date: string } The event service file is as follows: export class EventsService { eventDetailSubject = new Subject<any>(); constructor() { } sendEventDetail(event:

Async pipe not working with Subject

China☆狼群 提交于 2019-12-12 09:08:46
问题 I have the following BehaviorSubject in a service: isAuthenticated = new BehaviorSubject<boolean>(false); And I am using it as follows in a component: authenticated: Observable<boolean>; constructor(private accountService: AccountService) { } ngOnInit() { this.authenticated = this.accountService.isAuthenticated.asObservable(); } And in the template I do something like : <li class="login-button" *ngIf="!authenticated | async"> <a (click)="authenticate()">Log in</a> </li> <li *ngIf=

RXJS: Single Observable from dynamically created Observables

南笙酒味 提交于 2019-12-12 04:27:52
问题 I am trying to create an observable (fixedObservable here) which will be fed by multiple dynamically created observable over time. Whenever a subscription is made than the subscriber should get the most recent value from the fixedObservable. Although I have achieved it but I wanted to know if there is any simple solution to it. You can find the code here https://jsfiddle.net/dzm2t3pa/8/ . Thanks var resultdiv = document.getElementById('result'); function print(message) { var paraEl = document

Subject and Observable, how to delete item, filter() list and next()

送分小仙女□ 提交于 2019-12-11 00:12:48
问题 I have a list of songs setup with Subject and Observable (shown with | async in view), and now I want to delete a song off the list, do some filter() and call next() on the Subject. How and where do I filter? Right now I am doing getValue() on Subject and passing that to next() on, well, Subject. This just seems wrong and circularish. I also tried subscribing to the Subject and getting the data that way, filtering it and calling next() inside subscribe() , but I got a RangeError. I could

RxJs Subject error - cannot read property 'subscribe' of undefined

吃可爱长大的小学妹 提交于 2019-12-06 14:26:01
问题 In my service method that returns Observable I'm trying to notify the component via Subject that an action completed. completed: Subject<boolean> constructor(private http: Http) { } loadItems(): Observable<FrontItemDto[]> { return this.http.get ( `${ServiceSettings.ApiUrl}/front` ) .map ( res => { res.json (); if ( res.json () ) { this.completed.next ( true ); } } ) .catch ( (error: any) => Observable.throw ( error.json ().error || 'Server error' ) ); } This is how the component is listening

Async pipe not working with Subject

╄→尐↘猪︶ㄣ 提交于 2019-12-04 17:19:32
I have the following BehaviorSubject in a service: isAuthenticated = new BehaviorSubject<boolean>(false); And I am using it as follows in a component: authenticated: Observable<boolean>; constructor(private accountService: AccountService) { } ngOnInit() { this.authenticated = this.accountService.isAuthenticated.asObservable(); } And in the template I do something like : <li class="login-button" *ngIf="!authenticated | async"> <a (click)="authenticate()">Log in</a> </li> <li *ngIf="authenticated | async"> <a>Logged in</a> </li> The issue is that I dont see any of the two li , although the

Angular2:RxJS Subject not responding to events

房东的猫 提交于 2019-12-02 08:41:05
问题 I maintain a table which is generated from array of objects in which on click on a row would give an object which contain data of that one particular row.I needed to share it with all other components no matter it is a parent,child or sibling and and hence i use Subject,similar to https://embed.plnkr.co/P8xCEwSKgcOg07pwDrlO/. The problem i face is, on click, I assume event isnot getting emitted due to which I see nothing being reflected in another component. PLease let me know where i went

How can PublishSubject and BehaviorSubject be unsubscribed from?

天大地大妈咪最大 提交于 2019-11-29 20:36:06
Under the subjects package you have classes like PublishSubject and BehaviorSubject which I suppose can be described as some usable sample Observables . How can these subjects be unsubscribed from? There is no unsubscribe method and calling onCompleted ends the Observable altogether right? Septem A Subject is an Observable and an Observer at the same time, it can be unsubscribed from just like normal observables. what makes subject special is that it is sort of bridge between observables and observers. it can pass through the items it observes by reemitting them, and it can also emit new items

Getting current state in ngrx

巧了我就是萌 提交于 2019-11-29 12:47:48
Here is the solution for getting the current state in ngrx. The example is simple - you just use take(1) . But in rxjs documentation for take it says: Returns a specified number of contiguous elements from the start of an observable sequence How come taking the first value gets the current state (i.e. the last value)? Also I'm having trouble mocking this behavior in unit tests using Subject . The ngrx-store is a ReplaySubject of length=1 , this means only 1(the latest) value is cached and replayed on subscribe - so take(1) will resolve to the latest value. 来源: https://stackoverflow.com

How can PublishSubject and BehaviorSubject be unsubscribed from?

ⅰ亾dé卋堺 提交于 2019-11-28 16:15:22
问题 Under the subjects package you have classes like PublishSubject and BehaviorSubject which I suppose can be described as some usable sample Observables . How can these subjects be unsubscribed from? There is no unsubscribe method and calling onCompleted ends the Observable altogether right? 回答1: A Subject is an Observable and an Observer at the same time, it can be unsubscribed from just like normal observables. What makes subject special is that it is sort of bridge between observables and