最新的Google Angular 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

然而,当我把angular的版本改为1.0.1。页面显示正常

新版本有什么变化吗?

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

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

你还需要一个应用程序提供者。

<html ng-app="app">

你需要定义模块和控制器…cdn:

没有问题
<html ng-app="app">

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

看jsbin: jsbin

相关内容

  • 没有找到相关文章

最新更新