我在我的父组件中,我想检测发出的事件。
child.component.ts
@Component({
selector: 'child-component',
templateUrl: './child.component.html',
styleUrls: ['./child.component.scss']
})
export class ChildComponent implements OnInit {
@Input() public state: String = 'CLOSED';
@Output() public stateChanged: EventEmitter<String> = new EventEmitter<String>();
this.stateChanged.emit(this.state);
}
父组件.html
<router-outlet (stateChanged)="onStateChange($event)"><router-outlet>
父组件.ts
onStateChange(event){
console.log(event);
}
这对我不起作用!
编译后的 HTML 代码如下所示:
<router-outlet></router-outlet>
<child-component>
// all child component code
<child-component>
有没有办法推(stateChanged)="onStateChange($event)"
入<child-component>
元素?
有人可以帮忙吗?