I have in my parent component, where I want to detect the emitted event.
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);
}
parent.component.html
<router-outlet (stateChanged)="onStateChange($event)"><router-outlet>
parent.component.ts
onStateChange(event){
console.log(event);
}
This doesn't work for me!
The compiled HTML code looks like:
<router-outlet></router-outlet>
<child-component>
// all child component code
<child-component>
Is there any way to push (stateChanged)="onStateChange($event)"
in <child-component>
element?
Can anyone help, please?