javascript - Angular view not updating according to model -
my angular view not updating when update model. have tried calling $scope.apply() no avail.
<div ng-repeat="(key,value) in day.items track $index"> <label class="item item-input item-select"> <div class="input-label"> {{key}} </div> <select ng-model="value[$index].itemname" ng-options="item item item in equipment.{{key}}"> <option value="">select option</option> </select> </label> <label class="item item-input"> <input type="number" ng-model="value[$index].value" placeholder="amount/value"> </label> <button class="button button-balanced button-outline button-block" ng-click="additem(day,key)"> add {{key}} </button> </div>
and in controller:
$scope.additem = function(day,key) { day.items[key].push({itemname : '', value : ''}); }
what doing wrong? if log out day.items[key] additem method, has been successful in pushing new object array, it's not displaying it.
to 2-way binds model controllers variable you'll need specify in ng-model scope.array , not directly value.
i can't test right now, should :
<label class="item item-input" ng-repeat="(key, value) in day.items"> {{key}}<input type="text" ng-model="day.items[key].itemname"> </label >
update
i don't know how app should exaclty like, compare problem fiddle. in fiddle, model correctly binded.
Comments
Post a Comment