作为 customparameters:CustomParameter [] 我将ng-service中的值通过我的ng-component推送到html视图。在那里,我想更改值:
<ul>
<li *ngFor="let customparameter of customparameters">
<label>
<input [(ngModel)]="customparameter.wert" />
</label>
</li>
<p>
<button (click)="save(customparameters)">Speichern</button>
</p>
</ul>
如何将更改后的值现在传回我的ng-service?
这不起作用:
纳克成分:
//...
customparameters: CustomParameter[];
//...
save(customparameters: CustomParameter[]) {
this.customParameterService.setCustomParameters(this.customparameters);
}
//...
NG-服务
//...
customparameters: CustomParameter[];
//...
setCustomParameters(customparameters) {
console.log(this.customparameters); //still undefined
console.log(this.customparameters.length); //should be 5 but undefined
}
//...
日志显示
TypeError:this.customparameters未定义
有没有人对我有简短的最佳做法?谢谢!
答案 0 :(得分:2)
删除所有&#34;此&#34;应该管用。 &#34; this.customparameters&#34;是指你在组件中声明的customparameters,它从未被设置为未定义
save(customparameters: CustomParameter[]) {
this.customParameterService.setCustomParameters(customparameters);
}
setCustomParameters(customparameters) {
console.log(customparameters);
console.log(customparameters.length);
}