无法更新选择列表的ngmodel

时间:2015-05-11 09:31:32

标签: angularjs

案例: 我试图在控制器内部更新ng-model的值,但它不起作用,我想知道为什么,任何想法?

HTML

  <select ng-model="dumm" ng-options="item.name as item.type for (name, item) in availableFilters" ng-change="selectFilter()"></select>

JS

$scope.selectFilter = function () {
     $scope.availableFilters[$scope.dumm].visible = true;
     $scope.dumm = "";
};

  $scope.availableFilters = {
    name: {
        type: 'Name',
        name: 'name'
    },
    producttype: {
        type: 'Product type',
        name: 'producttype',
        data: $scope.xxx
    },
    status: {
        type: 'Status',
        name: 'status',
        data: $scope.unitStatusTypes
    }
}; 

1 个答案:

答案 0 :(得分:2)

$scope.dumm应该是一个对象而不是一个字符串,否则绑定不会起作用 - 这个事实在Angular的文档中非常模糊。绑定应如下所示:

<select ng-model="dumm.value"...

和变量的定义:

$scope.dumm = {value: ""};