Can you use @ViewChild() or similar with a router-outlet? How if so?
You may tap into activate event to get reference of instantiated component inside the router outlet.
excerpt from RouterOutlet Docs
A router outlet will emit an activate event any time a new component is being instantiated, and a deactivate event when it is being destroyed.
example
@Component({
selector: 'my-app',
template: `<h3 class="title">Basic Angular 2</h3>
<router-outlet (activate)="onActivate($event)" ></router-outlet>
`
})
export class AppComponent {
constructor(){}
onActivate(componentRef){
componentRef.sayhello();
}
}
@Component({
selector: 'my-app',
template: `<h3 class="title">Dashboard</h3>
`
})
export class DashboardComponent {
constructor(){}
sayhello(){
console.log('hello!!');
}
}
Here is the Plunker!!
Hope this helps!!