AngularJS:来自bootstrap-ui手风琴的访问范围

时间:2013-07-10 20:20:21

标签: angularjs angular-ui

我试图在ui-bootstrap手风琴中观察模特的变化。绑定在视图中工作,但是当模型更改时,$ watch不会触发。

http://plnkr.co/edit/DcoGT2?p=preview

如何在控制器中获取$ scope.myModel的值?

1 个答案:

答案 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);
  })
}

Plunker