我正在尝试传递在 a 中选择的对象来更新另一个对象的数据。这是html
<select id="categoryListBox"
ng-model="category.selected"
ng-change="updateCategory(category.selected)"
ng-options="category._id as category.name for category in categories">
</select>
这呈现
<select id="categoryListBox"
ng-model="category.selected"
ng-change="updateCategory()"
ng-options="category._id as category.name for category in categories"
class="ng-valid ng-dirty">
<option value="0" selected="selected">Test4</option>
<option value="1">Test5</option>
</select>
这是我的更新功能
$scope.updateCategory = function(){
console.log('hi');
}
我的问题是,现在当所选项目更改时 updateCategory 方法不会触发。我希望在<select></select>
我的 $scope.updateCategory 方法触发的更改中选择的选项。如果我可以将选择的类别传递给此方法,那也很棒。
此处更新是填充数组类别的我的初始化
$scope.init = function (){
console.log('dfakjsdhf');
console.log(apiUrl);
$scope.category = {};
$scope.subcategory = {};
//$scope.categories = {_id: 1, name:'test'};
$http({ method: 'GET', url: apiUrl + '/categories'}).
success(function (data, status, headers, config) {
$scope.categories = data;
console.log($scope.categories);
}).
error(function (data, status, headers, config) {
console.log('error');
});
};