Skip to content Skip to sidebar Skip to footer

This.myservice.myevent.torx().subscribe() Called But No Dom Refresh (zone Trigger)

I'm playing with angular2 alpha 40 with ng2-play starter from pawel. Examples are in typescript. I have a service MovieList like this: export class Movie { selected: boolean = fa

Solution 1:

The problem seems to be the fact that subscribe expects an Observer or three functions that work as an observer while you are passing a normal function. So in your code I just changed movieChanged to be an Observer instead of a callback function.

movieChanged: Observer = Observer.create(
    (f) => { this.currentMovie = f; }, // onNext(err) => {},                       // onError() => {}                           // onCompleted
  );

See this plnkr for an example. It would have been nice to see a minimal working example of your requirement so my solution would be closer to what you are looking for. But if I understood correctly this should work for you. Instead of a select I just used a button to trigger the change.

Update

You can avoid creating the Òbserver just by passing a function to the subscriber method (clearly there's a difference between passing directly a function and using a class method, don't know really why is different)

this.movieList.selectMovie.toRx().subscribe((m: Movie = null) => {
    this.currentMovie = m;
});

Note

EventEmitter is being refactored, so in future releases next will be renamed to emit.

Note 2

Angular2 moved to @reactivex/rxjs but in the plnkr I'm not able to use directly those libs (didn't find any cdn). But you can try in your own project using these libs.

I hope it helps.

Solution 2:

The movieChanged function expects the movie object and not the String. Try changing below code

setTimeout(() => { this.movieChanged('foo'); }, 4000);

to

setTimeout(() => { this.movieChanged(newMovie('Troy', 2000 , 8)); }, 4000);

Post a Comment for "This.myservice.myevent.torx().subscribe() Called But No Dom Refresh (zone Trigger)"