I'm trying to generate dynamically ng-model
directive in ng-repeat
but I receive an error from browser. We get dynamically attributes of a type and I would like to set its in DOM.
I'm recieving this error:
Error: [$parse:syntax] Syntax Error: Token '{' invalid key at column 2 of the expression [{{'attribute.'+attribute.label}}] starting at [{'attribute.'+attribute.label}}].
Click 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>
Do you have any idea which can help me to solve this problem? Thank you!
This isn't correct form and an error occurs if I tried but finally I did this and then I get the whole list of attributes. If change the input then change attribute.value into each attribute. It 's very tricky but works! Thank you!
<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="attribute.{{attribute.label}}"
don't use {{}} in ng-model. Use [] for dynamic ng-model. In your case use like this
<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>
where "value1" in ng-model is your input value. But remember use $scope.value = [] in your controller. I hope it helps you
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.