加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

使用Elvis运算符进行角度2 ngModel解析错误

发布时间:2020-12-17 07:30:22 所属栏目:安全 来源:网络整理
导读:嗨伙计们,我试图在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.in
嗨伙计们,我试图在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
  },
您需要将双向绑定拆分为一个数据和一个事件绑定:
[ngModel]="data?.insObj?.static && data.insObj.static['AHV,EO']?.employerShare" 
(ngModelChange)="data.insObj.static['AHV,EO'] && data.insObj.static['AHV,EO'].employerShare = $event"

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读