【发布时间】:2018-03-05 22:53:08
【问题描述】:
我的 html 代码中有一个 select 标记,如下所示:
<select ng-model="brandList" name="brandList" style="width:110px;" >
<option value="" selected>---Please select---</option>
<option ng-repeat="item in brandnameList | unique:'brandname'" value="{{item.brandname}}" style="width:50px;"> {{item.brandname}}</option>
</select>
我的选择中的值是通过 API 从数据库中获取的,代码如下所示。
adminService.getbrandnameList()
.then(function(data){
$scope.brandnameList = data.data;
$scope.brandn=data.data[0].brandname;
});
我有另一个函数需要选择标签上的选定值
$scope.ExportmodalAdmin = function () {
alert( $scope.brandList )
}
但是 $scope.brandList 的选择模型返回一个未定义的值。我怎样才能解决这个问题?我需要将 select 标记中的值传递给函数。
【问题讨论】:
-
发布您从
adminService.getbrandnameList()获得的 JSON 示例 -
您的代码是正确的,但您缺少定义变量 $scope.brandList = {};在方法 ExportmodalAdmin 之前
-
你能把你的代码贴出来吗
-
@Chandru,我在方法 exportmodalAdmin 之前定义了变量 $scope.brandList ={} 但它返回 {Object object} 响应
标签: javascript html angularjs select angular-ngmodel