0

我似乎无法使用 angularjs 路由加载 templateUrl。
使用 django 和 angularjs。
我要做的是转到127.0.0.1:8000/phones/,它将我重定向到127.0.0.1:8000/phones/#/
然后,我刷新,仔细检查。
在这两种情况下(第一次和刷新后)我只看到 TESTING 字符串。这是代码:

索引.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>

第一个.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 - 在更改为不缩小角度后添加浏览器的控制台:

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) 

谢谢你的时间

4

1 回答 1

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>

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

于 2014-07-31T17:18:45.407 回答