Angular不断抛出错误:undefined不是新ngDirective.controller的函数

时间:2013-10-03 14:39:59

标签: angularjs angularjs-directive

为了好玩,我创建了一个创建标签式导航的指令。 这是指令:

define(['angular'], function (ng) {
var directives = ng.module('directives', []);

/* top navigation tabs */
directives.directive('tabset', function () {
    return {
        restrict: 'E',
        scope: {},
        transclude: true,
        replace: true,
        templateUrl: 'common/components/directives/templates/tabset.tpl.html'
    };
})
.directive('tab', ['$location', function ($location) {
    return {
        restrict: 'E',
        replace: true,
        scope: {
            route: '@',
            title: '@'
        },
        link: function (scope, element, attrs) {
            var route = attrs.route;

            scope.location = $location;
            scope.active = false;

            scope.$watch('location.path()', function (new_route) {
                scope.active = route === new_route;
            });
        },
        templateUrl: 'common/components/directives/templates/tab.tpl.html'
    };
}]);

return directives;
});

Angular不断抛出此错误:

TypeError: undefined is not a function
at new ngDirective.controller (http://localhost:8080/uwr-tournament-handler/build/common/vendor/angular/angular.js:14357:5)
at invoke (http://localhost:8080/uwr-tournament-handler/build/common/vendor/angular/angular.js:3000:28)
at Object.instantiate (http://localhost:8080/uwr-tournament-handler/build/common/vendor/angular/angular.js:3012:23)
at http://localhost:8080/uwr-tournament-handler/build/common/vendor/angular/angular.js:4981:24
at http://localhost:8080/uwr-tournament-handler/build/common/vendor/angular/angular.js:4560:17
at forEach (http://localhost:8080/uwr-tournament-handler/build/common/vendor/angular/angular.js:137:20)
at nodeLinkFn (http://localhost:8080/uwr-tournament-handler/build/common/vendor/angular/angular.js:4545:11)
at compositeLinkFn (http://localhost:8080/uwr-tournament-handler/build/common/vendor/angular/angular.js:4191:15)
at compositeLinkFn (http://localhost:8080/uwr-tournament-handler/build/common/vendor/angular/angular.js:4194:13)
at compositeLinkFn (http://localhost:8080/uwr-tournament-handler/build/common/vendor/angular/angular.js:4194:13) 

我不知道为什么。我没有看到任何我尝试用作函数的undefined。 有人可以帮忙吗?

错误是不规则的,但大部分时间都是抛出的。 也许它与异步加载有关? 它似乎只发生在页面加载上,而不是在浏览网站时。

我在后台使用grunt。 我也使用requirejs。

除此之外,它似乎应该像它应该的那样工作。

tab.tpl.html:

<li data-ng-class="{active: active}">
    <a href="#{{route}}">{{title}}</a>
</li>

tabset.tpl.html:

<ul class="nav nav-tabs" ng-transclude></ul>

用法:

<tabset>
    <tab data-route="/home" data-title="Home"></tab>
    <tab data-route="/tournaments" data-title="Tournaments"></tab>
    <tab data-route="/about" data-title="About"></tab>
</tabset>

0 个答案:

没有答案