I want to pass data from child to parent component but it doesn't work in a proper way: function isn't invoked.
(我想将数据从子组件传递到父组件,但是它不能以适当的方式工作:未调用函数。)
<router-outlet (activeElement)='getActive($event)'></router-outlet>
<div class="myDIV">
<button *ngFor="let i of numberOfButtons" (click)="navigate(i)" [ngClass]="(i === active) ? 'btn active': 'btn'">{{i}}</button>
</div>
child component ts.file
(子组件ts.file)
@Output() activeElement = new EventEmitter();
constructor(private activatedRoute:ActivatedRoute,private getPlanets:GetPlanetsService,private router: Router, private renderer:Renderer2,private elRef: ElementRef) {
activatedRoute.params.subscribe(value=>{
this.fivePlanetIndex=value.id;
this.activeElement.emit(value.id);
});
}
parent component .ts file
(父组件.ts文件)
getActive(i){
console.log(i); //it is not invoked
}
ask by graluc translate from so