Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 角度错误:未定义不是new ngDirective.controller上的函数_Angularjs_Angularjs Directive - Fatal编程技术网

Angularjs 角度错误:未定义不是new ngDirective.controller上的函数

Angularjs 角度错误:未定义不是new ngDirective.controller上的函数,angularjs,angularjs-directive,Angularjs,Angularjs Directive,为了好玩,我创建了一个创建选项卡式导航的指令。 以下是指令: define(['angular'], function (ng) { var directives = ng.module('directives', []); /* top navigation tabs */ directives.directive('tabset', function () { return { restrict: 'E', scope: {}, tr

为了好玩,我创建了一个创建选项卡式导航的指令。 以下是指令:

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) 
我不知道为什么。我没有看到任何未定义的
函数。
有人能帮忙吗

错误是不规则的,但大多数情况下是抛出的。 也许这与异步加载有关? 这似乎只发生在页面加载时,而不是在浏览网站时

我在背景中使用咕噜声。 我也使用requirejs

除此之外,它似乎工作正常

tab.tpl.html:

<li data-ng-class="{active: active}">
    <a href="#{{route}}">{{title}}</a>
</li>
<ul class="nav nav-tabs" ng-transclude></ul>
  • tabset.tpl.html:

    <li data-ng-class="{active: active}">
        <a href="#{{route}}">{{title}}</a>
    </li>
    
    <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>
      
      
      
      最突出的是,您正在使用名为“location.path()”的函数,而不是属性。还有人能确认这是否可行吗?@MikeRobinson这在我这么做之前很久就是个问题,但它确实有效,至少在我的测试中是如此。我运行它没有问题。你能创建一个plunker吗?@Daiwei我的怀疑是is与指令无关,但我不知道,错误是抱怨
      ngDirective.controller
      。可能是我没有控制器吗?我将尝试创建一个,但现在没有时间。@kjelelook在另一个angular.module中是否需要此模块?或者这是您放入
      ng app
      的模块?如果是第一种情况,问题可能在其他地方。