Javascript AngularJs错误:[ng:areq]

Javascript AngularJs错误:[ng:areq],javascript,angularjs,angularjs-controller,Javascript,Angularjs,Angularjs Controller,我得到了一个[ng:areq]错误,可能很愚蠢,但我没有看穿它 做了一些研究,没有发现任何有用的东西 演示代码: <!DOCTYPE html> <html ng-app> <head lang="en"> <meta http-equiv="Content-Type" content="text/javascript; charset=utf-8" /> <title>Angular Third Example<

我得到了一个
[ng:areq]
错误,可能很愚蠢,但我没有看穿它

做了一些研究,没有发现任何有用的东西

演示代码:

<!DOCTYPE html>
<html ng-app>
<head lang="en">
    <meta http-equiv="Content-Type" content="text/javascript; charset=utf-8" />
    <title>Angular Third Example</title>
        <script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.3/angular.min.js"></script>
    <script>
        function NameCtrl($scope) {
          $scope.firstName = 'John';
          $scope.lastName = 'Doe';
        }
   </script>
</head>
<body ng-controller="NameCtrl">
    First Name: <input ng-model="firstName" type="text" />
    <br />

    Last Name: <input ng-model="lastName" type="text" />
    <br />

    Hello {{firstName}} {{lastName}}
</body>
</html>

第三个例子
函数名Ctrl($scope){
$scope.firstName='John';
$scope.lastName='Doe';
}
名字:

姓氏:
你好{{firstName}{{lastName}}
由于angular 1.3.x,您无法将控制器初始化为窗口函数。相反,您需要明确定义应用程序和控制器:

<!DOCTYPE html>
<html ng-app="myApp">
<head lang="en">
    <meta http-equiv="Content-Type" content="text/javascript; charset=utf-8" />
    <title>Angular Third Example</title>
        <script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.3/angular.min.js"></script>
    <script>
       angular.module('myApp', []).
       controller('NameCtrl', function($scope) {
          $scope.firstName = 'John';
          $scope.lastName = 'Doe';
       });
   </script>
</head>
<body ng-controller="NameCtrl">
    First Name: <input ng-model="firstName" type="text" />
    <br />

    Last Name: <input ng-model="lastName" type="text" />
    <br />

    Hello {{firstName}} {{lastName}}
</body>
</html>

第三个例子
angular.module('myApp',[])。
控制器('NameCtrl',函数($scope){
$scope.firstName='John';
$scope.lastName='Doe';
});
名字:

姓氏:
你好{{firstName}{{lastName}}
请不要使用这种声明。请使用基于模块的声明

ng app
无法识别所需的名称

var app = angular.module('app', []);
    app.controller('NameCtrl', ['$scope', function($scope) {
      $scope.firstName = 'John';
      $scope.lastName = 'Doe';
    }]);

演示

@ZiyadMestour您刚刚投了赞成票,需要通过单击答案左侧投票下方的勾号来接受。