要求模板的多个指令

Jue*_*tat 6 javascript angularjs angularjs-directive angular-template

错误:[$ compile:multidir]要求模板的多个指令[statbox,statbox]:

(在控制台上)

index.html里面

<script src="js/dashboard/dashboard.module.js"></script>
<script src="js/dashboard/dashboard.component.js"></script>
<script src="js/dashboard/statbox.component.js"></script>
Run Code Online (Sandbox Code Playgroud)

dashboard.module.js里面

var dashboardModule = angular.module('dashboard', ['ngRoute']);
Run Code Online (Sandbox Code Playgroud)

dashboard.component.js内

angular.module('dashboard').component('dashboard', {
templateUrl: 'templates/dashboard/dashboard.template.html',
controller: ['$scope', '$routeParams', '$http', '$rootScope', '$log', function DashboardController($scope, $routeParams, $http, $rootScope, $log) {
    ...stuff NOT REFERENCING STATBOX by any means...
}]
});
Run Code Online (Sandbox Code Playgroud)

statbox.component.js里面

angular.module('dashboard').component('statbox', {
templateUrl: 'templates/dashboard/statbox.template.html',
controller: ['$http', '$rootScope', '$log', function StatboxController($http, $rootScope, $log) {
    ... some random get request ...
}]
});
Run Code Online (Sandbox Code Playgroud)

app.js里面

var app = angular.module('buttonMasher', ['ngRoute', 'dashboard', ...]);
Run Code Online (Sandbox Code Playgroud)

dashboard.template.html里面

    ... stuff ...
    <div id="history">
        ... stuff ...

        <p><b>Statbox</b></p>
        <statbox></statbox>
    </div>
Run Code Online (Sandbox Code Playgroud)

statbox.template.html里面

<div id="statbox">
<p>{{$ctrl.statboxText}}</p>
Run Code Online (Sandbox Code Playgroud)

我做错了什么,为什么我会得到这个多指令错误?

每当我<script src="js/dashboard/statbox.component.js"></script> 从index.html 注释掉一切都有效但statbox控制器没有加载.

(完整项目在这里:Github:carloworks/masher - 一个人可以克隆并运行弹簧,启用配置文件"dev".)

Kar*_*rim 8

错误:[$ compile:multidir]要求输入模板的多个指令[statbox,statbox]

当您.js在index.html中包含两次并且绑定指令时编译器不知道要选择哪个模板时,很可能会发生此错误.

你应该检查:

  • 编译的html页面,看看你是否包含了两次statbox.js
  • 确保您的代码中没有多个位置来定义相同的位置 .component('statbox',{})

  • 为我工作..谢谢.错误地将js包括两次 (2认同)