角度误差:[$ compile:ctreq]无法找到指令'def'所需的控制器'abc'

时间:2014-11-16 18:19:22

标签: angularjs angularjs-directive

我已经按照教程阅读了文档但没有理解我做错了什么。我总是得到。这就是我拥有的

<!DOCTYPE html>
<html ng-app="myApp">
<head>
    <title></title>
    <script type="text/javascript" src="bower_components/angular/angular.js"></script>
    <script type="text/javascript" src="directives/communicate.js"></script>

    <script type="text/javascript">
        var app = angular.module('myApp', []);

        app.controller('abc', function($scope) {

        });

        app.directive('abd', function() {
            return {
                restrict: 'AE',
                controller: function($scope) {
                    $scope.tab = [];
                    console.log('hello')

                    this.tab = function() {
                        $scope.tab.push('test');
                    }
                }
            }
        });

        app.directive('def', function() {
            return {
                require: 'abc',
                link: function(scope, element, attrs, abcCtrl) {
                    console.log(abcCtrl.tab);
                }
            }
        });
    </script>
</head>
<body>
    {{ 1 + 1 }}
    <div def abc></div>
</body>
</html>

最后我总是得到错误:[$ compile:ctreq]无法找到指令&#39; def&#39;所需的控制器&#39; abc&#39;。怎么样?

1 个答案:

答案 0 :(得分:-2)

知道了!这是一个错字:(

app.directive('abd', function() {
...

应该是

app.directive('abc', function() {
...