Issue
I have an array of objects that are populated into a <select>
like so:
<label class="select" ng-show="standardFieldList.length > 0">
<select class="input-sm" ng-model="selectedStandardField" ng-change="addField('selectedStandardField')">
<option value="">Add Standard Field</option>
<option ng-repeat="item in standardFieldList" value="{{item}}" ng-if="!item.hide">{{item.value}}</option>
</select>
<i></i>
</label>
In Angular 1.5.5, {{item}}
will output a json representation of the object. However, having recently updated to 1.8.2, the output of {{item}}
is [object object]
. How can i get the JSON representation of the object into the value attribute?
Solution
The default behavior is changed from showing json representation to calling toString() method of the object which therefore returns [object Object]
<label class="select" ng-show="standardFieldList.length > 0">
<select class="input-sm" ng-model="selectedStandardField" ng-change="addField('selectedStandardField')">
<option value="">Add Standard Field</option>
<option ng-repeat="item in standardFieldList" ng-value="item" ng-if="!item.hide">{{item.value}}</option>
</select>
<i></i>
</label>
Try using ng-value When the ng-value directive is used to bind the item object to the element's value. When the item object is interpolated in the view, its JSON representatn will be used as the value of the element.
Answered By - Ganesh Nemade
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.