我有这个代码:
JS:
angular.module("module")
.controller("fooController", ["$scope", function($scope) {
...
})
.directive("foo", function() {
return {
restrict: "E",
controller: "fooController",
link: function($scope, $element, $attrs) {
// Do some things with the scope of the controller here
}
}
})
.directive("bar", function() {
return {
restrict: "E",
require: "fooController",
link: function($scope, $element, $attrs) {
// Nothing yet
}
}
});
Run Code Online (Sandbox Code Playgroud)
HTML:
<html>
<head>
<!-- Scripts here -->
</head>
<body ng-app="module">
<foo/>
<bar/>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
指令foo有效,但指令bar抛出错误:No controller: fooController. …
angularjs ×1