以下是使用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
时。页面显示正确。
新版本是否有任何改变?
答案 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