我试图在 ng-repeat
中动态生成 ng-model
指令,但我从浏览器收到错误消息。我们动态获取类型的属性,我想在 DOM 中设置它。
我收到这个错误:
Error: [$parse:syntax] Syntax Error: Token '{' invalid key at column 2 of the expression [{{'attribute.'+attribute.label}}] starting at [{'attribute.'+attribute.label}}].
点击here
<div class="form-group" ng-repeat="attribute in objectType.objectAttributes | orderBy : attribute.order">
<div class="col-sm-10" ng-if="attribute.multivalued==false">
<input type="{{attribute.type}}" class="form-control"
ng-model="{{'attribute.'+attribute.label}}">
</div>
</div>
你有什么想法可以帮助我解决这个问题吗? 谢谢!
最佳答案
这不是正确的形式,如果我尝试会发生错误,但最终我这样做了,然后我得到了整个属性列表。如果更改输入,则将 attribute.value 更改为每个属性。 这非常棘手但有效! 谢谢!
<div ng-repeat="attribute in indoor.values | orderBy : attributes[$index].order">
<input type="{{attributes[$index].type}}" class="form-control"
ng-model="attribute.value">
</div>
关于javascript - 动态 ng-model 到 ng-repeat AngularJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33083876/