我在控制器中定义了一个范围,如下所述:
控制器 :
var app = angular.module('app', ['ui.select2']);
app.controller('MyCtrl',
[
'$scope',
'$q',
'$timeout',
function ($scope, $, $timeout) {
$scope.data = {};
$scope.countries = [{
name : 'India', code : 'IA'
}, {
name : 'Israel', code : 'IS'
}];
$scope.selectedCountries = [
'IA'
];
$scope.$watch('selectedCountries', function(newValue, oldValue) {
console.log ('data');
});
]);
视图看起来像这样:
<select
ui-select2
multiple
ng-model="selectedCountries"
data-placeholder="Choose or Search for countries"
name="countries"
style="width:200px;">
<option ng-repeat="country in countries" value="{{country.code}}">{{country.name}}</option>
</select>
现在,当使用选择下拉列表在控制器中更改值时,值更改会反映在视图中。但是手表永远不会被调用,因为范围没有改变。知道为什么范围没有更新吗?