Мне нужно испустить строку, когда Родительская страница
<div class = "container-fluid fluidy">
<router-outlet (currentpage) = "componentAdded($event)"></router-outlet>
</div>
Parentpage.ts
componentAdded(stringer){
console.info(stringer);
this.currentpage = stringer;
}
Дочерняя страница
@Output() currentpage = new EventEmitter<string>();
ngOnInit(): void {
this.currentpage.emit('profile');
}
Если компонент запускается внутри router-outlet, он больше не является дочерним компонентом компонента, имеющего router-outlet. следовательно, обычно вывод на теге router-outlet не будет работать. Вместо этого вы можете сделать что-то вроде
HTML-код родительского компонента
<router-outlet (activate) = "componentActivated($event)" (deactivate) = "componentDeactivated($event)"></router-outlet>
Родительский компонент ts
componentAddedSubscription: Subscritption;
componentActivated(component) {
if (component instanceof ChildComponent) {
this.componentAddedSubscription = component.currentpage.subscribe(res=>{
//your logic
});
}
}
componentDeactivated(component) {
if (component instanceof ChildComponent) {
if (this.componentAddedSubscription?.unsubscribe) {
this.componentAddedSubscription.unsubscribe();
}
}
}