Hi Sander,

Thank's for your reply! 

If I understand you correctly, the Observable-route is preferable. You 
mentioning ngZone got me trying ngZone.run, which got rid of the 
detectChanges-call.
This means I can completely isolate components from knowing about 
communicating with legacy-js, by moving that code to a Service.

New plunkr at https://plnkr.co/edit/hXW9NCBDmQvqsjTYfBlE?p=info, where the 
significant change is:

constructor(private ngZone: NgZone) {
  app.oString = this.messageSource;
}

ngOnInit() {
  this.messageSource.subscribe(message => {
    console.log('Received message: ', message);
    this.ngZone.run(() => this.changeTitle(message));
  });
}


Would you consider this a good route to continue on?

// Jonas

PS. I'll post the broader question of porting the legacy app in a new 
question.DS

On Thursday, October 19, 2017 at 6:53:45 AM UTC+2, Sander Elias wrote:
>
> Hi Jonas,
>
> Took me a while to figure out what you are trying to do. 
> Don't create an interop by exposing internals of your angular app to the 
> outside. That will lead to all kind of unexpected results in the future. 
> The other way around is better. (also not without issues, but we got to 
> deal with legacy somehow!)
>
> Then about calling the changeDetector. You are right, this is a red flag. 
> This happens if you bootstrap your legacy app before your angular app. The 
> result of that is that your legacy app run's outside of the ngZone, and 
> changes are not detected. This might not be a problem, but you need to be 
> aware of this. If you boot your legacy app, after you have booted your 
> Angular app, this will work as expected. Everything then runs inside the 
> zone, and CD will do its work.
>
> I'm missing too much information on your legacy app to give a well-founded 
> advice about how you should plan your upgrade. There are a lot of scenarios 
> possible.
>
> Regards
> Sander
>

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to