从指令中的隔离范围观察控制器的范围

时间:2015-06-27 18:00:49

标签: javascript angularjs

我有一个下拉列表,在选择一个值时,我的控制器中的变量会被更改但是指令中的监视没有被触发

<select ng-model="storesid" ng-change="changeVal(storesid)" ng-options="store.name for store in stores">
                <option value="">
            </option>
                </select>

和使用它的控制器。

app.controller("segmentCtrl",function($scope,$rootScope,segmentService,lookupService){
    $scope.changeVal = function(item){
    $scope.timeSeries = item;
   }
})

和指令

我在看

.directive('timeseries1',function(){
return{
    restrict:'E',
    scope:{
      val:'='
    },
    link:function(scope,element,attrs){
        scope.$watch('timeSeries',function(){ 

        })   
    }
}
})
<div ng-controller="segmentCtrl">
 <timeseries1 id="dualAxisAreaContainer4" val="timeSeries" ></timeseries1> 
</div>

1 个答案:

答案 0 :(得分:0)

该变量被称为&#34; val&#34;在你的指令范围内。所以请注意这样做。

相关问题