I need to bring a select option
with the selected option being populated dynamically.
I have in my controller filling the list like this:
$scope.$watch('IdCategoria', function() {
$http.get("/api/Categoria/GetList", { }).success(function(response) {
$scope.categorias = response;
});
});
And my select
looks 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 newCtrl.IdCategoria
is the field with Id
of the selected category, in which select
should be selected.
I read here in the Stack that using track by
should work, but if I set track by newCtrl.IdCategoria
, both editing and registering I can not select another option. p>
I've also tried using ng-init
, but also to no avail:
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 have tested this way
<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>