最新的Google Angular CDN不起作用

时间:2016-08-22 01:11:57

标签: javascript angularjs google-cdn

以下是使用google angular js cdn的演示页面:

    <html ng-app>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
    </head>
    <body ng-controller="TextController">
        <p>{{mytext}}</p>
    </body>
    <script>
        function TextController($scope) {
            $scope.mytext = "hello world";
        }
    </script>
    </html>

我使用了最新的google angular js cdn。

它给出了一系列错误如下:

angular.js:13708 Error: [ng:areq] http://errors.angularjs.org/1.5.7/ng/areq?p0=TextController&p1=not%20a%20function%2C%20got%20undefined
at Error (native)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js:6:412
at sb (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js:22:508)
at Qa (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js:23:78)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js:89:273
at ag (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js:72:353)
at m (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js:64:218)
at g (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js:58:481)
at g (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js:58:498)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js:58:119(anonymous function) @ angular.js:13708

然而,当我将角度版本更改为1.0.1时。页面显示正确。

新版本是否有任何改变?

2 个答案:

答案 0 :(得分:2)

我不知道哪个版本,但控制器必须注册到de app。

var app = angular.module('app',[]);

app.controller('TextController', TextController);

你还需要一个app priveder。

<html ng-app="app">

答案 1 :(得分:1)

您需要定义模块和控制器...... cdn没有问题:

<html ng-app="app">

<script>
    angular.module('app', []).controller('TextController', TextController);
    ...

看看这个jsbin:jsbin