对于1.2.x的
只有做到这样,似乎是$watch
荷兰国际集团的$scope.selectedThing
:
$scope.selectedThing = aThing;
$scope.$watch('selectedThing', function() {
//do stuff here
});
一旦你在下拉列表中选择一个值,这将触发。
1.3-β
如果你想避免$watch
荷兰国际集团的变量,那么你可以使用即将ngModelOptions
:
<select ng-model="selectedThing"
ng-model-options="{getterSetter:true}"
ng-options="thing.name for thing in allThings">
而在你的控制器:
currentThing = aThing;
$scope.selectedThing = function (newThing) {
if (angular.isDefined(newThing)) {
console.log("setting new Thing", newThing);
currentThing = newThing;
}
return currentThing;
};
来源
2014-09-06 00:35:36
ray
不该”它是'getterSetter'的大写字母吗? – PSL 2014-09-05 23:41:45
适用于我.. http://plnkr.co/edit/o2AuIl?p=preview你有其他问题检查你的控制台是否有任何错误。那么你使用的角度版本是否支持它?尝试在重击中复制您的问题 – PSL 2014-09-05 23:47:53
控制台中没有错误,这很奇怪。我现在和你的朋友一起玩。 – ray 2014-09-05 23:52:17