我在Angular工作,我有字段填写像
我将选择列表填写为:
function cargarCatalogo() {
apiService.get("../../api/Catalogos/",
null,
function(res) {
//console.log(res.data);.
$scope.Catalogos = res.data;
$scope.selected = $scope.Catalogos[0];
},
errorCatalogo);
}
我想知道如何在我的函数中将选定的值传递给url:
function actualizar(vehiculo) {
$scope.vehiculo.Origen = $scope.usuario.Origen;
$scope.vehiculo.Version = $scope.Version;
apiService.post("../../api/AddCatalogoRegistro/" + selected.ID,
function(res) {
// my code
如何将选定的值作为selected.ID,chrome控制台传递给我
ReferenceError:未定义选定
查看:
<select class="form-control" ng-change="filtro(selected)" ng-init="Catalogos[0]" ng-model="selected" ng-options="item.Nombre for item in Catalogos">
<option></option>
</select>
答案 0 :(得分:2)
将$scope.selected
用作ng-model
值
<select class="form-control" ng-change="filtro(selected)"
ng-init="Catalogos[0]" ng-model="selected"
ng-options="item.Nombre for item in Catalogos">
它应该可以解决你的问题。最佳做法是命名控制器并使用ng-model = "ctrlName.selected"