在angularjs ver 1.3.0中使用ng-controller时出现错误

嗨,我正在跟随一些angularjs的教程

我正在使用angularjs版本1.3.0

这是我的代码

<div ng-app="" ng-controller="personController"> First Name: <input type="text" ng-model="firstName"><br> Last Name: <input type="text" ng-model="lastName"><br> <br> Full Name: {{firstName+" " + lastName}} </div> <script type="text/javascript"> function personController($scope) { $scope.firstName = "David"; $scope.lastName = "Silva"; } </script> 

而且我认为我已经完成了和教程一样的工作。 但是,当我用萤火虫检查时,它给了我下面的错误。

 Error: [ng:areq] Argument 'personController' is not a function, got undefined http://errors.angularjs.org/1.3.0/ng/areq? p0=personController&p1=not%20a%20function%2C%20got%20undefined 

如何摆脱这个?

在angular1.3.0你必须做下面,因为全局控制器被禁用1.3.0-β。 参考

 <div ng-app="myApp" ng-controller="personController"> 

 <script> var app = angular.module("myApp",[]); app.controller('personController', function($scope){ $scope.firstName = "David"; $scope.lastName = "Silva"; }) </script> 

它还表示,你可以通过使用下面的代码来获得较旧的行为, 但是它不被推荐

 <div ng-app="myApp" ng-controller="personController"> var app = angular.module("myApp",[]).config(['$controllerProvider', function($controllerProvider) { $controllerProvider.allowGlobals(); }]); function personController($scope) { $scope.firstName = "David"; $scope.lastName = "Silva"; }