AngularJS错误:$compile:multidir多指令资源争用
我正在尝试将我的应用程序的一部分分离成一个指令,但继续得到以下结果:AngularJS错误:$compile:multidir多指令资源争用,angularjs,templates,angularjs-directive,scope,compiler-errors,Angularjs,Templates,Angularjs Directive,Scope,Compiler Errors,我正在尝试将我的应用程序的一部分分离成一个指令,但继续得到以下结果: Multiple directives [tree (module: anbud), tree (module: anbud)] asking for template on: 这可能是由以下原因造成的: Multiple directives requesting isolated scope. Multiple directives publishing a controller under the same name
Multiple directives [tree (module: anbud), tree (module: anbud)] asking for template on:
这可能是由以下原因造成的:
Multiple directives requesting isolated scope.
Multiple directives publishing a controller under the same name.
Multiple directives declared with the transclusion option.
Multiple directives attempting to define a template or templateURL.
我的观点是这样的:
<tree></tree>
(function (module) {
var tree = function () {
return {
restrict: "E",
controller: "treeController",
templateUrl: "/app/NSviewer/templates/parts/tree.html"
};
};
module.directive("tree", tree);
}(angular.module("anbud")));
我的控制器更复杂:
(function () {
'use strict';
angular.module('anbud')
.controller('treeController', ['$scope', 'api', '$log', 'localStorage', 'jwt', function ($scope, api, $log, localStorage, jwt) {
// on successfull request
function onJson(json) {
//$scope.data = json;
console.log($scope.data)
// set default
$('#loading').hide();
$scope.data = {};
$scope.data[0] = {};
$scope.data[0].c = "NS 3420";
$scope.data[0].n = "2015";
$scope.data[0].i = json.i;
;
}
// error getting json
function onError(e) {
console.log('error:');
console.log(e);
if (e.status === -1) {
throw 'Fikk ikke tak i server, sjekk internetforbindelsen din. [404]';
} else if (e.status === 0) {
throw 'No connection. Verify application is running. [0]';
} else if (e.status == 404) {
throw 'Fikk ikke tak i server, sjekk internetforbindelsen din. [404]';
} else if (e.status == 401) {
throw 'Unauthorized [401]';
} else if (e.status == 405) {
throw 'HTTP verb not supported [405]';
} else if (e.status == 500) {
throw 'Internal Server Error [500].';
} else {
throw 'Noe gikk galt. [' + e.status + ']';
}
}
function onJsonPart(code, json) {
console.log('Code: ' + code);
console.log('json:');
console.log(json);
// validate JSON
if (angular.isUndefined(json)) {
$log.error('Mottok ingen JSON for ns kode: ' + code);
console.log('Mottok ingen JSON for ns kode: ' + code);
return;
}
// check for code in root node in json
console.log('$scope.data:');
console.log($scope.data);
if (angular.isUndefined($scope.data)) {
$log.error('Scope data is not defined');
return;
}
// TODO:
// Skal enten være 26 eller 27, vet ikke om 'Felles bestemmelser' skal være med
if (($scope.data[0].i.length !== 26 || $scope.data[0].i.length !== 27) === false) {
$log.error('NS koder er ikke lasted ned lokalt!');
return;
}
// loop gjennom layer 0 av treet
// get object containing all ns codes
var j = $scope.data[0];
// layer 0
for (var l0 = 0; l0 < j.i.length; l0++) {
// layer 1
for (var l1 = 0; l1 < j.i[l0].i.length; l1++) {
// fint node in tree
if (j.i[l0].i[l1].c === code) {
// append to tree
j.i[l0].i[l1].i = json.i;
return;
}
}
}
$log.error('Fant ikke NS kode: "' + code + '"');
}
// get json part to append to tree
$scope.get = function (code) {
// Kun layer 1, AB - AV, BE3 til BE8, CD, CH, CY etc
if (code.length > 3 || code.length < 2) {
$log.error('NS kode ikke godkjent!');
return;
}
api.get(code)
.then(
function (json) {
onJsonPart(code, json);
},
function (error) {
onError(error);
}
);
};
console.log('Getting JSON!');
api.getFirstThreeLayers().then(onJson, onError);
}]);
}());
(函数(){
"严格使用",;
角模('anbud')
.controller('treeController',['$scope','api','$log','localStorage','jwt',function($scope,api,$log,localStorage,jwt){
//请求成功后
函数onJson(json){
//$scope.data=json;
console.log($scope.data)
//设置默认值
$(“#加载”).hide();
$scope.data={};
$scope.data[0]={};
$scope.data[0].c=“NS 3420”;
$scope.data[0].n=“2015”;
$scope.data[0].i=json.i;
;
}
//获取json时出错
函数onError(e){
console.log('error:');
控制台日志(e);
如果(如状态==-1){
抛出“Fikk ikke tak i服务器,sjekk internetforbindelsen din.[404]”;
}否则如果(如状态===0){
抛出“无连接。验证应用程序正在运行。[0]”;
}否则如果(如状态==404){
抛出“Fikk ikke tak i服务器,sjekk internetforbindelsen din.[404]”;
}否则,如果(e.status==401){
抛出“未经授权的[401]”;
}否则如果(如状态==405){
抛出“不支持HTTP谓词[405]”;
}否则,如果(如状态==500){
抛出“内部服务器错误[500]”;
}否则{
抛出“Noe gikk galt.['+e.status+']”;
}
}
函数onJsonPart(代码,json){
console.log('代码:'+代码);
log('json:');
log(json);
//验证JSON
if(angular.isUndefined(json)){
$log.error('ns kode的Mottok ingen JSON:'+代码);
log('ns kode的Mottok ingen JSON:'+代码);
返回;
}
//检查json中根节点中的代码
console.log(“$scope.data:”);
log($scope.data);
if(angular.isUndefined($scope.data)){
$log.error('未定义范围数据');
返回;
}
//待办事项:
//斯卡尔·恩滕·维奥尔26岁,埃勒27岁,兽医ikke om“Felles Bestemelser”斯卡尔·维奥尔医学院
if($scope.data[0].i.length!==26 | |$scope.data[0].i.length!==27==false){
$log.error('NS koder er ikke last ned lokalt!');
返回;
}
//环路gjennom第0层av树
//获取包含所有ns代码的对象
var j=$scope.data[0];
//第0层
对于(var l0=0;l03 | |代码长度<2){
$log.error('NS kode ike godkjent!');
返回;
}
api.get(代码)
.那么(
函数(json){
onJsonPart(代码,json);
},
函数(错误){
误差;
}
);
};
log('get JSON!');
getFirstThreeLayers().then(onJson,onError);
}]);
}());
不知道是什么导致了这个问题 这可能是由于应用程序两次包含角度 您应该在浏览器开发人员控制台中看到一些警告,Angular已经初始化了两次 在包含AngularJS文件的HTML文件中验证相同
另一个原因是,当您两次包含某些指令时,这些指令正在创建隔离作用域或试图呈现模板。控制台中没有警告。。不要认为Angular会被调用两次。好的,你能展示一下你使用
树的HTML代码片段吗!