我似乎无法使用angularjs路由加载templateUrl
使用django和angularjs
我所做的是转到 127.0.0.1:8000/phones / ,它将我重定向到 127.0.0.1:8000/phones /#/
然后,我刷新,仔细检查。
在这两种情况下(第一次和刷新后)我只看到TESTING字符串。这是代码:
的index.html
{% load staticfiles %}
<!DOCTYPE html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"> </script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.20/angular-route.min.js"></script>
<script>
var phones = angular.module('phones', ['ngRoute']);
phones.config(function($interpolateProvider){
$interpolateProvider.startSymbol('{[{');
$interpolateProvider.endSymbol('}]}');
});
phones.config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/', {
templateUrl: "{% static "partials/first.html" %}",
}).otherwise({
redirectTo: "/"
});
}]);
</script>
</head>
<body ng-app="phones">
<div ng-view></div>
TESTING
</body>
</html>
first.html
HELLO
从runserver控制台:
[31/Jul/2014 18:40:46] "GET /phones/ HTTP/1.1" 200 1488
[31/Jul/2014 18:40:48] "GET /phones/ HTTP/1.1" 200 1488
[31/Jul/2014 18:40:48] "GET /static/partials/first.html HTTP/1.1" 304 0
正如您所看到的,angularjs路由确实请求HTML,但它仍然没有显示。
我遇到的另一个问题是控制台输出。 为什么它只在我刷新时才发送(或只显示)first.html的GET请求? 我希望路由首次请求first.html ..
修改 添加浏览器的控制台:
TypeError: undefined is not a function
at v (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.20/angular-route.min.js:6:357)
at g.$broadcast (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:102:324)
at http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.20/angular-route.min.js:11:179
at C (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:91:121)
at C (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:91:121)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:92:288
at g.$eval (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:100:198)
at g.$digest (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:98:82)
at g.$apply (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:101:12)
at g (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:66:321) angular.js:9037
编辑#2 - 在更改为非缩小角度后添加浏览器控制台:
TypeError: undefined is not a function
at update (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.20/angular-route.js:871:25)
at Scope.$broadcast (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.js:11803:28)
at http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.20/angular-route.js:552:26
at wrappedCallback (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.js:10549:81)
at wrappedCallback (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.js:10549:81)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.js:10635:26
at Scope.$eval (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.js:11528:28)
at Scope.$digest (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.js:11373:31)
at Scope.$apply (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.js:11634:24)
at done (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.js:7635:45)
感谢您的时间
答案 0 :(得分:1)
你包含了错误的AngularJS版本。
改变这个:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"> </script>
到此:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.20/angular.min.js"> </script>
这花了太长时间才搞清楚!