3
votes

this is the error i m getting.This question is asked many time. But the following code runs well in online compiler but not in my local system even the system is connected to internet then also it shows angular is not defined

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>
1
Post your complete code - Sajeetharan
where is the reference for angular and ngRoute? - Sajeetharan

1 Answers

3
votes

Change your controller like this,

  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>