gpt4 book ai didi

angular - 带有动态变量的 ngModel

转载 作者:搜寻专家 更新时间:2023-10-30 21:16:31 25 4
gpt4 key购买 nike

当使用 ngModel 将值发射到属性从 bumpDetail.name 数组获取的 bump 对象时,我遇到了一些问题。

我已经在下面粘贴了我的代码片段。
谁能帮我检查一下,告诉我哪里做错了?谢谢。

<p *ngFor="let bumpDetail of bumpDetail">
<input type="checkbox" id="device" [(ngModel)]={{bump.bumpDetail.name}}/>
<label for="device">{{bumpDetail.name}}</label>
</p>
 Bump[] = [{
"name": "bump_1",
"status": true
}, {
"name": "bump_2",
"status": false
}, {
"name": "bump_3",
"status": true
}]

这是错误。

Parser Error: Got interpolation ({{}}) where expression was expected at column 0 in [{{bumpDetail.name}}] in ng:///AppModule/SettingComponent.html@129:59 ("p *ngFor="let bumpDetail of bumpDetail">

最佳答案

[]{{}} 从不一起使用。一个或另一个

[(ngModel)]="this[bumpDetail.name]"

{{}} 仅用于字符串插值。

关于angular - 带有动态变量的 ngModel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47221026/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com