无法使用控制器作为语法从自定义指令更新控制器模型值

时间:2015-06-01 07:21:31

标签: angularjs angularjs-directive angularjs-scope angularjs-controller

我在使用控制器作为语法从custom指令更新我的模型值时遇到问题。我可以清楚地看到,通过console.log,指令中的值会发生变化,但是它们在控制器中没有得到更新。 <h4>{{self.tabs}} </h4>始终显示相同的值。

另外我想在控制器(自我&gt;标签)模型上观看添加'活动类'但是当我尝试使用手表时它会让我失误。所以我评论了那一部分。以下是与手表相关的代码,它不起作用:

$scope.$watch('tabsCtrlself.tabs.index', function() {
          if (tabsCtrlself.tabs.index === index) {
            angular.element($element).addClass('active');
          }
        });

请找到我的plunker,任何人都可以指导我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

you can use 'ng-class' attribute,eg:
<en-tab data-pane="myPaneName1" ng-class="{active:index==1}">Tab #1</en-tab>
<en-tab data-pane="myPaneName2" ng-class="{active:index==2}" >Tab #2</en-tab>
<en-tab data-pane="myPaneName3"  ng-class="{active:index==3}">Tab #3</en-tab>
'index' is a object in angular: $scope.index, initializes its value:
 $scope.index=1;
The first item is selected by default.

I think the object of 'tabsCtrl.tabs.index' is not a angular object, so can't auto refresh