DanWahlin / Angular-JumpStart

Angular and TypeScript JumpStart example application

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unused router instance in app.component.ts

riscie opened this issue · comments

Hi Dan

I am not 100% sure but in my opinion, there is no need to instantiate the router instance within the app.component.ts constructor method. If I understand typescripts instance modifiers correctly, the private one does not allow us to use the instance of the router within classes deriving from the app-container component. If that is true, couldn't we just remove the constructor completely?

constructor(private router: Router) {
}

Thanks for this example and all your helping resources!

Cheers Matthias

I have the same question....and being mildly bit obsessive compulsive always wanting to know why?!

I repeated in my mind:

  1. Router is a service that should be injected into whatever module that needs it.
  2. You should not access the router from another module/class through inheritance because you would couple things together.

So are you parking the implementation of the private router constructor in the app-container and leaving it there to expand the example later? The tour of heroes sample on Angular.io looks to be using the deprecated router...

Thank you for everything you do Dan, your sample is really helping me make sense of Angular 2.

Alex

It was added since the alpha version of the router wouldn't work properly otherwise (one of those weird scenarios). The new alpha of the router just came out though which changes everything so I'll be updating the project as soon as I get time.