未捕获错误:[$ injector:modulerr] http://errors.angularjs.org/1.4.8/$injector/modulerr?p0=myApp&p1=Error

时间:2015-12-07 11:47:09

标签: javascript angularjs

this is the error i m getting.很多时候会问这个问题。但是下面的代码在在线编译器中运行良好但在我的本地系统中运行不好,即使系统连接到互联网,那么它也显示角度未定义



angular.module('myApp',[]).controller('myCtrl',function($scope) {
    $scope.firstName = "John";
    $scope.lastName = "Doe";
});

<html>
  <body>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">

First Name: <input type="text" ng-model="firstName"/><br>
Last Name: <input type="text" ng-model="lastName"/><br>
<br>
Full Name: {{firstName + " " + lastName}}

</div>
    </body>
  </html>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:3)

像这样改变你的控制器,

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

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular-route.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
  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>
  var app = angular.module('myApp', ['ngRoute']);
  app.controller('myCtrl', function($scope) {
    $scope.firstName = "John";
    $scope.lastName = "Doe";
  });
</script>