我有这样的选择:
<select class="form-control" ng-hide="Catalogos.length==0"
ng-change="filtro(selected)" ng-model="selected"
ng-options="item.Nombre for item in Catalogos ">
</select>
从那里我得到selected value
这样的函数:
$scope.filtro = function(selected) {
$scope.selectedID = selected.ID;
}
我Id
获得selected value
,但现在我将它用于另一个函数,但是该函数可以获取参数null或者不是,因此函数是:
$scope.insertar = function () {
if ($scope.catalogoid != null) {
var url = "../../api/Catalogo/UpdateCatalogoRegistro/" + $scope.Codigo + "/" + $scope.Nombre + "/" + $scope.catalogoid + "/" + $scope.Catalogo;
if ($scope.selected.ID != null) {
url = url + "/" + $scope.selected.ID;
}
apiService.post(url....
问题是当它变为空时它只是在通过此验证时抛出$scope.selected is undefined
if ($scope.selected.ID != null) {
url = url + "/" + $scope.selected.ID;
}
如果在这种情况下不存在$scope.selected
,我该如何验证呢?
答案 0 :(得分:1)
您已将其存储在$scope.selectedID
中,但是从$scope.selected.ID
检索。
使用
if ($scope.selectedID != null) {