我有这个代码:
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
      }
    }
  });
HTML:
<html>
  <head>
    <!-- Scripts here -->
  </head>
  <body ng-app="module">
    <foo/>
    <bar/>
  </body>
</html>
指令foo有效,但指令bar抛出错误:No controller: fooController.
如何在保持当前结构的同时解决此问题(控制器不在 HTML 中,但由指令使用,bar在外部foo并共享同一个控制器,而两者都在修改其范围)?我在这里阅读了讨论,但我不明白该怎么做。