I have a very simple scenario of subscribing to an Observable via an injected FooService
:
foo.service.ts
:
@Injectable()
export class FooService {
private foosSubject = new Subject<FooModelDTO[]>();
constructor() {
this.setFoos([{id: "Some Id"}]);
}
setFoos(foos) {
console.log("FooService.setFoos", foos);
this.foosSubject.next(foos);
}
onFoos(): Observable<FooModelDTO[]> {
return this.foosSubject.asObservable();
}
}
app.componenet.ts
:
export class AppComponent {
private fooSubscription: Subscription;
constructor(private _fooService: FooService) {
this.fooSubscription = this._fooService.onFoos()
.subscribe({
next: this.handleSubscription.bind(this)
});
}
handleSubscription(foosModels: FooModelDTO[]) {
console.log("Yes!!!!"); <--- I'm not getting here!
}
}
My question:
Why I'm am not able to fire the handleSubscription
method via subscribe
's next
?