What's the best practice if you want to control the navigation from a service?


#1

After updating my app to 2.0.0-beta.7/Angular 2.0.0-rc.1 I cannot get a reference to the nav inside a service. I’ve tried the @ViewChild and NavController methods but both fail. I’m not an Angular expert so, is this normal behaviour?

I’ve also read that it might be a bad practice to control the view from a service and it should be done via events instead. Is that correct?


#2

#3

Actually using getActiveNav() fixes my issue.


#4

I absolutely think so. Services should live in service-land, completely independent of component-dom-land. Personally, every time I’ve felt the need to do what you’re doing, I’ve eventually ended up yelling at myself and redoing the design.


#5

Oh, that’s so honest. The endpoint of yelling at yourself, and starting again, is all too familiar along the learning path :slight_smile: