2015-10-14 60 views
0

我的index.html文件,我試圖加載該HTML文件中的指令。 //試圖加載角度不止一次,同時創建自定義指令

{% extends "base.html" %} 
{% load staticfiles %} 
{% block content %} 
<div ng-app="myApp"> 
<div ng-controller="mainController"> 
{% verbatim %} 
<div class="row"> 
<div class="column small-12"> 
<h1 class="up heading text_setting">{{title}}</h1> 
</div> 
</div> 
<edit-cart></edit-cart> 
<div class="row"> 
<div class="small-12 column"><h1 class="up heading">products total <span class="right">3000</span></h1> </div> 
</div> 
<div class="row"> 
<div class="small-10 block-center"> 
<button class="btn-block up heading text_setting ">checkout as guest</button> 
<button class="btn-block up heading text_setting">log in/join</button> 
</div> 
</div> 
</div> 
{% endverbatim %} 
</div> 
{% endblock content %} 
{% block customjs %} 
<!-- common angular js --> 
<script src="{% static 'angular_wrapper/shared/angular.min.js' %}"></script> 
<script src="{% static 'angular_wrapper/shared/angular-route.js' %}"></script> 
<script src="{% static 'angular_wrapper/shared/angular-mock.js' %}"></script> 

<!-- app --> 
<script src="{% static 'angular_wrapper/shared/app.js' %}"></script> 
<!-- controller --> 
<script src="{% static 'angular_wrapper/controller/maincontroller.js' %}"></script> 
<!-- directives --> 
<script src="{% static 'angular_wrapper/directives/directive-editcart.js' %}"></script> 
<!-- angular services --> 
<script src="{% static 'angular_wrapper/services/service-editcart.js' %}"></script> 
{% endblock customjs %} 

editcart.html是本 //

<div class="row"> <P>{{move.name}}</P> <P>{{move.email}}</P> </div>

和角代碼 //

var app = angular.module('myApp', ['ngRoute']); 
app.controller('mainController', ['$scope', function($scope) { 
    $scope.move={ 
     name:'sonu', 
     email:'[email protected]' 
    }; 
}]); 
//directive 
app.directive('editCart', function() { 
    return { 
    restrict: 'E', 
    templateUrl: 'directives/editcart.html' 
    }; 
}); 

console-image attached here

我正在爲我的Web應用程序創建自定義指令,但無法修復此錯誤。 不知道什麼是錯的。

我已經包括了所有的js請幫忙嗎?

+1

也許你正試圖加載角度不止一次? :) –

+0

@EdHinchliffe nope。 我已經過檢查它。 代碼或指令等錯誤 –

+1

你能鏈接你的HTML嗎?恐怕角度不太可能會因爲這個錯誤消息而對你撒謊,所以你很可能會在某處加載兩個角度的副本。 –

回答

2

正如this Michael Bromley發佈的GitHub問題(第二個答案),問題在於Angular試圖實例化一個它無法找到的模板,所以它只是重新加載index.html文件,其中包含角度腳本,所以錯誤。

我通過在templateUrl指示從公共目錄(或者您正試圖採取從該文件的一個)的根文件的完整路徑解決了這個問題。

所以在我的情況是modules/teams/client/directives/notification.html insk directives/notification.html

我不知道,如果這是正確的解決方案,但爲我工作。

我真的很失望的是,角沒有告訴我這個缺失的模板,但當我把modules/directive(這是一個文件夾),它給了我一個錯誤。

真的很奇怪的行爲,我預計至少被告知模板未正確加載。

相關問題