2
I need to bring one select option
with the selected option being filled dynamically.
I have in my controller the filling of the list so:
$scope.$watch('IdCategoria', function() {
$http.get("/api/Categoria/GetList", { }).success(function(response) {
$scope.categorias = response;
});
});
And mine select
is like this:
<select ng-model="newCtrl.IdCategoria" required class="form-control" data-live-search="true" ng-options="c.Value as c.Text for c in categorias">
<option value="">Selecione uma categoria</option>
</select>
Where the newCtrl.IdCategoria
is the field with the Id
of the selected category, in which the select
should come selected.
I read here on Stack that using the track by
should work, but if I set track by newCtrl.IdCategoria
, both in editing and registration I can not perform the selection of another option.
I’ve tried using the ng-init
, but also without success:
ng-init="newCtrl.IdCategoria= newCtrl.categorias[newCtrl.IdCategoria]"
Remembering that my categories are:
[{"Value":"24","Text":"Categoria 1"},{"Value":"25","Text":"Categoria 2"}]
EDIT1 I’ve tested it like this
<select ng-model="newCtrl.IdCategoria" required class="form-control" data-live-search="true">
<option value="">Selecione uma categoria</option>
<option ng-repeat="c in categorias" value="{{c.Value}}">{{c.Text}}</option>
</select>
Have you looked at documentation?
– Ivan Ferrer
Yes... I don’t know if it’s because of the dynamic information but it doesn’t work at all.. I’ve even tried using ng-repeat no options and nothing!
– Ivan Teles