Output
will work by using component selector, not with router-outlet
.
(Output
将通过使用组件选择器而不是router-outlet
起作用。)
Because router-outlet
used to render multiple components and it doesn't make sense to set all Input
s and Output
s on there.(因为router-outlet
用来渲染多个组件,所以在此处设置所有Input
和Output
都没有意义。)
If you wanna use router-outlet
and catch events from children components, you can use Observable
s;
(如果您想使用router-outlet
并从子组件中捕获事件,则可以使用Observable
;)
where child component send result and parent component subscribe to it.(子组件发送结果,父组件订阅该结果。)
sample.service.ts
(sample.service.ts)
// you will use subject to emit event from child
subject = new Subject<any>();
// you will use observable to listen to events from parent
observable = this.subject.asObservable();
child.component.ts
(child.component.ts)
constructor(service: SampleService) {}
// instead of emit function
this.service.subject.next();
parent.component.ts
(parent.component.ts)
constructor(service: SampleService) {}
// instead of event listener
this.service.observable.subscribe();
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…