2 years ago

#19152

test-img

Sonali

Broadcasted values from Angular Library Project not getting received

I have an angular 12 library project from which I am trying to broadcast some values using behaviorsubject and shared service.

Here is my broadcast service code:

@Injectable({ providedIn: 'root' })
export class BroadcastService{
public subject = new BehaviorSubject<any>(null);

get(){
return this.subject.asObservable();
   }

broadcast(data: any){
     this.subject.next(data);
   }
}

} }

In my sample application which is consuming this angular library project. I am subscribing to this broadcast service in onInit hook using:

this.broadcastService.get().subscribe(data => handleData(data) );

But only the default value(null) is getting received at subscriber in sample application. Other broadcasted values from library project is not getting received in sample application's component.

When I am debugging .next() method of RxJS it is saying subscriber count is 0.

angular

rxjs

observer-pattern

behaviorsubject

rxjs-observables

0 Answers

Your Answer

Accepted video resources