我正在使用Angular在WebApi Asp.Net工作,我想知道如何使用select
填充简单的下拉列表查看:
<select class="form-control input-sm" name="Catalogo" id="Catalogo" ng-change="filtro('Cat')" ng-model="f.Cat">
<option value="" selected>TODOS</option>
<option ng-repeat="item in Catalogos" value="{{item.Nombre}}" label="{{item.Nombre}}"></option>
</select>
<br />
角度控制器:
(function (app) {
'use strict';
app.controller('catalogosGenericosCtrl', catalogosGenericosCtrl);
catalogosGenericosCtrl.$inject = ['$scope', 'apiService', 'notificationService', '$rootScope', '$location', '$http', '$state'];
function catalogosGenericosCtrl($scope, apiService, notificationService, $rootScope, $location, $http, $state) {
if ($rootScope.Usuario.TipoPerfil != 'Administrador')
$state.go("root.dashboard");
$scope.loadingConductores = true;
$scope.usuario = {};
$scope.usuario.Origen = 'Web'
$scope.usuario.Version = $rootScope.VersionWeb;
$scope.page = 0;
$scope.pagesCount = 0;
$scope.Catalogos = [];
cargarCatalogo();
function cargarCatalogo() {
apiService.get("../../api/Catalogos/", null,
function (res) {
$scope.Catalogos = res.data.Nombre;
},
errorCatalogo);
}
function errorCatalogo(res) {
bootbox.alert("Error al cargar el catalogo" + res.data);
}
}
})(angular.module('myPortal'));
console.log(res.data)
获得10个不同的值,如:
CatalogoPadreId:0
ID:"BAN"
Nombre:"BANKS"
从那里我只想把“Nombre”值变成`res.data ;, chrome控制台没有显示任何错误,而且我的下拉列表没有任何价值,我怎样才能在我的下拉列表中获得Nombre值?什么是我的代码在那里?
答案 0 :(得分:0)
使用ng-options代替ng-repeat,
<select ng-change="filtro(selected)" ng-model="selected" ng-options="item.Nombre for item in Catalogos">
</select>