Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了使用Elvis运算符进行角度2 ngModel解析错误大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
嗨伙计们,我试图在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">

当我更改输入字段时,它会引发错误

我正在将这个从对象转换为像这样的组件中的数组

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
  },
您需要将双向绑定拆分为一个数据和一个事件绑定:
[ngModel]="data?.insObj?.static && data.insObj.static['AHV,EO']?.employerShare" 
(ngModelChangE)="data.insObj.static['AHV,EO'] && data.insObj.static['AHV,EO'].employerShare = $event"

大佬总结

以上是大佬教程为你收集整理的使用Elvis运算符进行角度2 ngModel解析错误全部内容,希望文章能够帮你解决使用Elvis运算符进行角度2 ngModel解析错误所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。