指令和变量

Directives and variables

提问人:user880386 提问时间:6/26/2015 最后编辑:mccainzuser880386 更新时间:6/26/2015 访问量:22

问:

我的指令中按以下方式控制和链接:

myapp.directive('MyDirective', function(){
    return{
        restrict: 'A',
        transclude: true,
        scope: {
          ....
        },
        controller: function($scope) {
           $scope.variable = true;

        },
        templateUrl:  './app/templates/template.html',
        link: function(scope, element, attrs){
            scope.$watch('variable ', function(){
            console.log("variable : " + scope.variable )
          });
       }
       .....

我无法在块链接中看到scope.variable。我该如何解决?

angularjs 作用域 angularjs-scope using 指令

评论

0赞 Razvan B. 6/26/2015
再看看如何使用$watch
0赞 ryanyuyu 6/26/2015
“阻止链接”是什么意思?请同时包含相关的 HTML。如果您尝试监视不在指令隔离范围内的变量,您可能正在寻找类似的东西scope.$parent.$watch()
0赞 user880386 6/26/2015
我将 $scope.variable 定义为指令的控制器。我想在scope.watch中使用它。我可以尝试使用scope.$parent.$watch

答: 暂无答案