2016-03-11 216 views
0

當我在/#/ addOrder中輸入URL時,它將加載模板文件。沒錯,我得到一些錯誤和索引頁面加載兩次。未找到路由控制器

t.html

{% load staticfiles %} 
<!DOCTYPE html> 
<html> 
<head> 
    <title>asdad</title> 
</head> 
<body> 
<div ng-app = "mainApp"> 
<a href="#/addOrder">add</a> 
    <div ng-view></div> 

</div>  
</body> 

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js"></script> 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular-route.min.js"></script> 
<script src="{% static 'js/script.js' %}" type="text/javascript"></script> 
</html> 

tem.html

<h1>tem is loaded!</h1> 

script.js 

var mainApp = angular.module("mainApp", ['ngRoute']); 
mainApp.config(['$routeProvider', function($routeProvider) { 
$routeProvider. 

when('/addOrder', { 
    templateUrl: 'tem.html', controller: 'activeOrderController' 
}). 

when('/viewStudents', { 
    templateUrl: 'order/addOrders.html', controller: 'addOrderController' 
}). 
when('/viewStudents', { 
    templateUrl: 'order/endedOrders.html', controller: 'endedOrderController' 
}). 

otherwise({ 
    redirectTo: '/t.html' 
}); 

}]); 

Error: ng:areq Bad Argument

Argument 'activeOrderController' is not aNaNunction, got undefined Description AngularJS often asserts that certain values will be present and truthy using a helper function. If the assertion fails, this error is thrown. To fix this problem, make sure that the value the assertion expects is defined and truthy.

enter image description here

+1

不引起錯誤的控制器,但要注意你的'otherwise'需要在一個定義的有效角度URL時' ' – charlietfl

回答

0

嘗試納克應用內和 「=」 之間取出空的空間。 ng-app =「mainApp」

另外,創建兩個你在路由配置中引用的控制器。

0

您錯誤的重定向語句&您有兩條路線與/viewStudents相同的語句的名稱。

otherwise({ 
    redirectTo: '/viewStudents' 
}); 

你也必須定義所有這些都是何況還有每條路線

mainApp.controller('activeOrderController', function(){ 
    //console.log('I am activeOrderController') 
}) 
mainApp.controller('addOrderController', function(){ 
    //console.log('I am addOrderController') 
}) 
mainApp.controller('endedOrderController', function(){ 
    //console.log('I am endedOrderController') 
}) 
+0

現在我遇到了崩潰,http://pastebin.com/8tGtV9gH –