gpt4 book ai didi

javascript - Angular 路线不会加载 templateUrl

转载 作者:行者123 更新时间:2023-12-03 12:08:37 27 4
gpt4 key购买 nike

我似乎无法使用 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

从运行服务器控制台:

[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 - 在更改为非缩小 Angular 后添加浏览器控制台:

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)

感谢您的宝贵时间

最佳答案

您添加了错误版本的 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>

这花了太长时间才弄清楚!

关于javascript - Angular 路线不会加载 templateUrl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25063643/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com