我有一个有角度的应用程序,我希望将结果导入select
,所以我将其作为:
HTML
<div class="col-xs-12 col-sm-6 col-md-4">
<div class="form-group">
<label>Register: </label>
<select class="form-control" ng-options="item.Nombre for item in GetCatalogoPadre"></select>
<br />
</div>
</div>
AngularCtrl
function cargarCatalogo() {
apiService.get("../../api/Catalogo/GetCatalogoPadre/", null,
function (res) {
$scope.Catalogos = res.data;
}, errorCatalogo);
控制器
namespace PortalDeTransporte.Web.Controllers
{
//[Authorize]
[RoutePrefix("api/Catalogo")]
public class CatalogoRegistroController : ApiControllerBase
{
[System.Web.Http.AllowAnonymous]
[System.Web.Http.HttpGet]
[Route("GetCatalogoPadre")]
public HttpResponseMessage GetCatalogoPadre(HttpRequestMessage request)
{
//some code there for get results
}
return response;
});
}
}
如果我尝试使用带有GET操作的邮递员获得结果,那么就会发生一些异常情况:
http://localhost:55720/api/Catalogo/GetCatalogoPadre
我得到了正确的结果:
{
"ID": "1",
"Codigo": "BMX",
"Nombre": "BANAMEX",
"Padre": 0,
"Catalogo": "BAN"
},
{
"ID": "2",
"Codigo": "KNW",
"Nombre": "KENWORTH",
"Padre": 0,
"Catalogo": "MAR"
},
但是他们没有出现在选择列表中,有人可以在代码中查看错误吗?此致
答案 0 :(得分:0)
应该是,
import cv2
还确保您在 <select class="form-control" ng-options="item.Nombre for item in Catalogos "></select>
ng-init
<强>样本强>
<div class="form-group" ng-init="cargarCatalogo()">
<label>Register: </label>
<select class="form-control" ng-options="item.Nombre for item in Catalogos"></select>
<br />
</div>
&#13;
var myApp=angular.module('myApp',[]);
myApp.controller('thecontroller',function($scope){
$scope.cargarCatalogo = function (){
$scope.catalogos = [{
"ID": "1",
"Codigo": "BMX",
"Nombre": "BANAMEX",
"Padre": 0,
"Catalogo": "BAN"
},
{
"ID": "2",
"Codigo": "KNW",
"Nombre": "KENWORTH",
"Padre": 0,
"Catalogo": "MAR"
}];
};
});
&#13;