Last active
December 25, 2015 01:19
-
-
Save chaosim/6894484 to your computer and use it in GitHub Desktop.
why can not find required controller?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.directive('foo', [ | |
'$log', function($log) { | |
return { | |
restrict: 'E', | |
replace: true, | |
transclude: true, | |
template: '<div id="test" ng-transclude></div>', | |
controller: function($scope) { | |
this.scope = $scope; | |
return $scope.panes = []; | |
}, | |
link: function(scope, element, attrs) { | |
return $log.log('test1', scope.panes); | |
} | |
}; | |
} | |
]); | |
module.directive('bar', [ | |
'$log', function($log) { | |
return { | |
restrict: 'E', | |
replace: true, | |
transclude: true, | |
require: '^?foo', | |
controller: function($scope) { | |
return this.x = 1; | |
}, | |
template: '<div ng-transclude></div>', | |
link: function(scope, element, attrs, fooCtrl) { | |
return $log.log('test2', fooCtrl); | |
} | |
}; | |
} | |
]); | |
// below is the piece of html: | |
<foo ng-controller="IndexController"> | |
<bar></bar> | |
</foo> | |
// below is the element generated, inspected from chrome developer tools | |
<div id="test" ng-transclude="" ng-controller="IndexController" class="ng-scope"> | |
<div ng-transclude="" class="ng-scope"></div> | |
</div> | |
// below is console output: | |
test2 | |
Array[0] | |
length: 0 | |
__proto__: Array[0] | |
angular.js:5930 | |
test1 | |
Array[0] | |
length: 0 | |
__proto__: Array[0] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
帮你提交到这, 好分析点: http://plnkr.co/edit/aM81utpVPwYoI6ru28rT?p=preview
不过没看懂你想做什么。
this.scope = $scope;
和return this.x = 1;
这两句代码干嘛的? 为啥要用this