Combobox Dinâmico co Angular JS
by Ivan Ferrer
HTML
<html ng-app="seuApp">
<body ng-controller="ACtrl" ng-init="abrirCombobox()">
<select name="selecao" class="form-control" id="selecao" required class="form-control" data-live-search="true"
ng-options="option.Text for option in categorias.availableOptions track by option.Value"
ng-model="categorias.selectedOption"><option value="">Selecione uma categoria</option></select>
</body>
</html>
JavaScript
angular
.module('seuApp', [])
.controller('ACtrl', ['$scope',
function($scope) {
$scope.categorias = {};
$scope.abrirCombobox = function() {
var response = [{"Value":"24","Text":"Categoria 1"},{"Value":"25","Text":"Categoria 2"}];
if (response.length > 0) {
$scope.categorias = {
availableOptions: response,
selectedOption: {
Value: response[0].Value,
Text: response[0].Text
}
};
console.log( $scope.categorias );
}
};
}]);