我有四个乘积(A,B,C,D)值(在标记之间)。 我创建了一个角度的子组件,我想通过EventEmitter.emit将一个好的值(A或B或Cor D)传递给父组件,但用户单击却不能。我总是发送第一个值A。 这是我的角度代码
component.html
<table>
<thead>
<th><a #ca [attr.data-cat]="alax" (click)="getName(ca.dataset.cat)">A</a></th>
<th><a #ca [attr.data-cat]="beter" (click)="getName(ca.dataset.cat)">B</a></th>
<th><a #ca [attr.data-cat]="colar" (click)="getName(ca.dataset.cat)">C</a></th>
<th><a #ca [attr.data-cat]="dera" (click)="getName(ca.dataset.cat)">D</a></th>
</thead>
</table>
在component.ts中
alax= 'ARMOIRS';
beter= 'PARASOLS';
colar= 'CAMBOUS';
dera= 'DIAMBRE';
@Output()
sendRequestData = new EventEmitter();
getName(catName:string) {
console.log("catName nom : "+catName);
this.sendRequestData.emit(catName);
}
在父亲component.html中,我有:
<app-chilComponent (sendRequestData)="treatment($event)"></app-childComponent>
在父component.ts中
treatment(message: any){
console.log(message) // I have always 'ARMOIRS' when I click on A or B or C or D
// I want to have 'ARMOIS' when I click on A and 'PARASOLS' when i click on B
}
任何的想法 ?
You have used the same selector
#ca
for all. Change them希望能帮助到你!