0

I would like to observe the event inside of one componenet and then fire diffrent event i another one. I have declare service and such code inside

    private updateIncomingMaterial = new Subject<IncomingMaterial>();

    incomingMaterialUpdate$ = this.updateIncomingMaterial.asObservable();

   updateIncMaterial(incomingMaterialToUpdate: IncomingMaterial) {
       this.updateIncomingMaterial.next(incomingMaterialToUpdate);
   }

There is how i fire event in one component

    update(model: IncomingMaterial) {
    this.incMatService.updateIncMaterial(model);
    this.isEditorVisible = true;
    this.isUpdateMode = true;
}

and here how i want to subscribe it in another one

    ngAfterViewInit() {
    this.subscription = this.incMatService.incomingMaterialUpdate$.subscribe((model: IncomingMaterial) => {
        this.isUpdateMode = true;
        this.imForm.setValue(model);
    });
}

I dont know why it never go inside of subscription in the fist time when i click update button(inside i mean this.UpdateMode = true and this.imForm.setValue(model)).

Stefan
  • 1,431
  • 2
  • 17
  • 33
  • why are you going down on rxjs and not using Angular Output properties? (see: https://angular.io/docs/ts/latest/guide/template-syntax.html#!#inputs-outputs ) – E. Hein Jan 03 '17 at 11:52
  • Are both components existing and have the view initialized when you click? – olsn Jan 03 '17 at 11:55
  • Because one of them is parent component and i dont know if Output properties is working in such case? – Stefan Jan 03 '17 at 11:55
  • The view is propably initialized couse is subscripe inside of ngAfterViewInit it goes inside but in first not inside of subscription if I click second time it works – Stefan Jan 03 '17 at 11:59
  • Ok i had to use ReplaySubject instead of Subject, now it works fine :) – Stefan Jan 03 '17 at 12:14

0 Answers0