动态 ng-model 到 ng-repeat AngularJS
Dynamic ng-model into ng-repeat AngularJS
我正在尝试在 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>
你有什么想法可以帮助我解决这个问题吗?
谢谢!
你可以这样做:
ng-model="attribute.{{attribute.label}}"
这不是正确的形式,如果我尝试了会发生错误,但最终我这样做了,然后我得到了整个属性列表。如果更改输入,则将 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>
不要在 ng-model 中使用 {{}}。将 [] 用于动态 ng-model。在你的情况下这样使用
<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="value1[attribute.label]">
</div>
其中 ng-model 中的 "value1" 是您的输入值。但请记住在您的控制器中使用 $scope.value = [] 。希望对你有帮助
我正在尝试在 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>
你有什么想法可以帮助我解决这个问题吗? 谢谢!
你可以这样做:
ng-model="attribute.{{attribute.label}}"
这不是正确的形式,如果我尝试了会发生错误,但最终我这样做了,然后我得到了整个属性列表。如果更改输入,则将 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>
不要在 ng-model 中使用 {{}}。将 [] 用于动态 ng-model。在你的情况下这样使用
<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="value1[attribute.label]">
</div>
其中 ng-model 中的 "value1" 是您的输入值。但请记住在您的控制器中使用 $scope.value = [] 。希望对你有帮助