我在Angular2中尋找AngularJS ISolated(= operation)作用域的類似功能。
我想更改子組件中的父組件值,以便我不需要使用任何EventEmitter。
以下是我的代碼片段。
如何在angular2中更新父組件的父組件
<component-1>
<div *ngFor="let row of listArray" >
<component-2 [inputData]="row.inputData" (outputEvent)= "onComponentChange($event)"> </component-2>
</div>
<component-2 [inputData]="inputData2" (outputEvent)= "onComponentChange($event)"> </component-2>
<component-2 [inputData]="inputData3" (outputEvent)= "onComponentChange($event)"> </component-2>
<component-2 [inputData]="inputData4" (outputEvent)= "onComponentChange($event)"> </component-2>
@Component
component-1{
onComponentChange(newValue){
//where to keep the new value
//this.inputData2/inputData3/inputData4/listArray[i].inputData ???????????
}
}
@Component
component-2{
@Input() inputData:string;
@Output() outputEvent:EventEmitter<string>;
changeComponentValue(newValue){
this.outputEvent(newValue);
}
}
我將在部件-2變更[inputData]的值,即應在組件1反映。
在現有的@Output eventEmitter中,我無法找到要更改的元素值。
你想改變的價值?或者只是想知道你正在處理哪個元素? – micronyks