i just, can't figure out how set ng-model contain value of select, , not object self.
html
<select name="status" data-ng-model="search.status" data-ng-options="s.label s in statuses"> </select> $scope.statuses = [ { label: ' - si/no - ', value: '' }, { label: ' migrated ', value: 0 }, { label: ' active ', value: 1 }, { label: ' canceled ', value: 2 }, { label: ' un-confirmed ', value: 3 }, ]; $scope.search.status = $scope.statuses[0]; and result be:
stdclass object ( [label] => - si/no - [value] => ) now, want [value], , not whole object. how can achieve that?
p.s. don't want have access object->value, want x variable, contain value.
update
i had before, , working:
<select name="status" class="txt" data-ng-model="search.status"> <option value=""> - - </option> <option value="0"> migrated </option> <option value="1"> active </option> <option value="2"> canceled </option> <option value="3"> un-confirmed </option> </select> my search.status contain selected value, , not whole object code above.
you need change markup. as keyword in ng-options expression makes magic.
the expression below sets object property s.value model s.label still remains label <option> element (i think want).
<select name="status" ng-model="search.status" ng-options="s.value s.label s in statuses"> </select> and of course, model value initialization in controller has modified (as @orangepill noted):
$scope.search.status = $scope.statuses[0].value;
Comments
Post a Comment