-1

I am working on a simple application of AngularJs. I use cloud9 as an Ide and install Angular through bower in my project, but still get an error "angular not defined" in my .js file. Here is my code please help me.

index.html

<!DOCTYPE html>
<html ng-app="myApp">
<head>
  <title>BlogIt!</title>
  <script type="text/javascript" src="bower_components/angular/angular.min.js"></script>
  <script type="text/javascript" src="app.js"></script>
</head>
<body ng-controller="myCtrl">
  {{message}}
</body>
</html>

app.js

var app = angular.module('myApp', []);

app.controller('myCtrl', function($scope) {
  $scope.message = "Welcome to BlogIt!";
})
31piy
  • 23,323
  • 6
  • 47
  • 67

3 Answers3

1

You are not able to load angular.min.js on your page.

Try by changing like this:

<script type="text/javascript" src="bower_components/angular/angular.min.js"></script>

to

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>

var app = angular.module('myApp', []);

app.controller('myCtrl', function($scope) {
  $scope.message = "Welcome to BlogIt!";
})
<!DOCTYPE html>
<html ng-app="myApp">
<head>
  <title>BlogIt!</title>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
  <script type="text/javascript" src="app.js"></script>
</head>
<body ng-controller="myCtrl">
  {{message}}
</body>
</html>
Ritesh Ranjan
  • 1,012
  • 9
  • 16
  • Please don't poke the OP for answer's acceptance. If this is the correct answer, OP will eventually accept it. – 31piy Jan 05 '18 at 05:53
0

You are missing ng-app

<body ng-app="myApp" ng-controller="myCtrl">
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
0

Add ng-app in your program.

It's the starting point of the application.