我试图在ui-bootstrap手风琴中观察模特的变化。绑定在视图中工作,但是当模型更改时,$ watch不会触发。
http://plnkr.co/edit/DcoGT2?p=preview
如何在控制器中获取$ scope.myModel的值?
答案 0 :(得分:7)
使用对象而不是基元:
<div ng-controller="AccordionDemoCtrl">
<accordion>
<accordion-group heading="Static Header">
<input ng-model="model.myModel"> {{ model.myModel }}
</accordion-group>
</accordion>
</div>
angular.module('plunker', ['ui.bootstrap']);
function AccordionDemoCtrl($scope) {
$scope.model = {myModel: ''};
$scope.$watch('model.myModel',function(){
console.log($scope.model.myModel);
})
}