在 AngularJs 中,我们如何在其他指令模块控制器中使用注册的控制器$scope对象


app.controller('myController',['$scope',function($scope){
$scope.temp = '007'; // my controller variable
}]);
app.directive('mydir', function() { 
  return {
    restrict: 'A',
    transclude: true,
    scope: { mydirobj: '=mydir' },
    link: function(scope, element, attrs)
    {
      console.log(scope.temp);
     // here i am trying to access 'myController' controller scope var
     // getting error
    }
  };
});
app.controller('myController', ['$scope',
    function($scope) {
        $scope.temp = '007'; // my controller variable
    }
]);
app.directive('mydir', function() {
    return {
        restrict: 'A',
        transclude: true,
        controller: 'myController', // add it here
        scope: {
            mydirobj: '=mydir'
        },
        link: function(scope, element, attrs) {
            console.log(scope.temp);
            // here i am trying to access 'myController' controller scope var
            // getting error
        }
    };
});

您可以看到我的内联评论。

相关内容

  • 没有找到相关文章

最新更新