Skip to content

Instantly share code, notes, and snippets.

@tytskyi
Created September 6, 2017 10:05
Show Gist options
  • Save tytskyi/4fafa7e61f7a1665102e1af6f5a1dc3b to your computer and use it in GitHub Desktop.
Save tytskyi/4fafa7e61f7a1665102e1af6f5a1dc3b to your computer and use it in GitHub Desktop.

angular/angular#11228 (comment)

@Component({
  ...
  providers: [MyService],
  template: '<router-outlet></router-outlet>'
})
export class MyNavWrapperComponent {
  // Must inject to instantiate service for all child routes.
  // When this component is destroyed, the service will be too.
  constructor(service: MyService) { }
}

routes: Routes = [
  {
    path: '',
    component: MyNavWrapperComponent,
    children: [ ... ],
  }
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment