嗨伙计们,我试图在AngularJs中进行双向绑定,我得到了这个错误
Parser Error: The '?.' operator cannot be used in the assignment at column 48 in [data.insObj.static['AHV,IV,EO']?.employerShare=$event]
我的ngModel看起来像这样
[(ngModel)]="data.insObj.static['AHV,EO']?.employerShare"
我怎样才能解决这个问题 ?
UPDATE
我有这个代码
<input type="text" class="form-control" id="employerShare" name="data.insObj.static['AHV,EO'].employerShare" placeholder="5.125%" [ngModel]="data.insObj.stat['AHV,EO']?.employerShare" (ngModelChange)="data.insObj.static['AHV,EO'].employerShare = $event">
当我更改输入字段时,它会引发错误
Cannot read property ‘AHV,EO’ of undefined
我正在将这个从对象转换为像这样的组件中的数组
this.data.insObj.stat = response.body.static; this.data.insObj.stat = this.convertObj(response.body.static);
我将它转换为数组的函数如下所示:
public convertObj(obj) { var custObj = []; var array = $.map(obj,function (value,index) { custObj[index] = value; }); return custObj; }
你可以帮我解决这个问题,为什么会在ngModelChange中失败
"static": { "AHV,EO": { "id": 19,"employerShare": "0.05125","employeeShare": "0.05125","numberOfCompensationFound": "123.456","insuranceNumber": "278.12312.123.456","insuranceName": null,"man": null,"woman": null,"customerNumber": null,"subNumber": null,"contractNumber": null,"upperLimit": null,"isSuva": null,"dateOfContribution": "2017-03-02T08:30:01.095Z","yearOfContribution": 2017,"createdAt": "2017-03-02T08:30:01.095Z","updatedAt": "2017-03-06T11:02:22.323Z","insuranceContributionHeaderId": 11,"companyId": 12,"insuranceContributionHeader.id": 11,"insuranceContributionHeader.insuranceName": "AHV,EO","insuranceContributionHeader.isFixed": true },
您需要将双向绑定拆分为一个数据和一个事件绑定:
原文链接:https://www.f2er.com/angularjs/142202.html[ngModel]="data?.insObj?.static && data.insObj.static['AHV,EO']?.employerShare" (ngModelChange)="data.insObj.static['AHV,EO'] && data.insObj.static['AHV,EO'].employerShare = $event"