AngularJS:从 bootstrap-ui 手风琴访问范围 [英] AngularJS: access scope from bootstrap-ui accordion
本文介绍了AngularJS:从 bootstrap-ui 手风琴访问范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试 $watch 以查看 ui-bootstrap 手风琴中模型的更改.绑定在视图中起作用,但是当模型更改时,$watch 不会触发.
http://plnkr.co/edit/DcoGT2?p=preview
如何在控制器中获取 $scope.myModel 的值?
解决方案
使用对象而不是原始类型:
<手风琴><accordion-group 标题="静态标题"><输入 ng-model="model.myModel">{{ 模型.myModel }}</accordion-group></手风琴>
angular.module('plunker', ['ui.bootstrap']);函数 AccordionDemoCtrl($scope) {$scope.model = {myModel: ''};$scope.$watch('model.myModel',function(){console.log($scope.model.myModel);})}
I'm trying to $watch for a change on a model within a ui-bootstrap accordion. Binding works within the view, but when the model changes, the $watch doesn't fire.
http://plnkr.co/edit/DcoGT2?p=preview
How do I get the value of $scope.myModel in the controller?
解决方案
Use an object rather than a primitive:
<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);
})
}
这篇关于AngularJS:从 bootstrap-ui 手风琴访问范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文