user2860954 user2860954 - 4 months ago 21
AngularJS Question

Reference Error - angular not defined

the following is my app.html - template where i will be injecting my other partial views as to come,

<html ng-app="billApp">
<head>
<!-- SCROLLS -->
<!-- load bootstrap and fontawesome via CDN -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" />
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.0.0/css/font-awesome.css" />

<!-- SPELLS -->
<!-- load angular via CDN -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular-route.js"></script>
<script src="script.js"></script>
</head>

<!-- define angular controller -->
<body ng-controller="mainController">

...

<!-- MAIN CONTENT AND INJECTED VIEWS -->
<div id="main">
{{ message }}

<!-- angular templating -->
<!-- this is where content will be injected -->
</div>
</body>
</html>


And this is the script.js file which is the controller for the application,

// script.js

// create the module and name it scotchApp
var billApp = angular.module('billApp', []);

// create the controller and inject Angular's $scope
billApp.controller('mainController', function($scope) {

// create a message to display in our view
$scope.message = 'Everyone come and see!';
});


while i try to run the script.js file using my commandline


  1. change directory to nodejs directory

  2. type in 'node path-of-the-project-file\script.js'



which throws the following error,
var billApp = angular.module('billApp', []);
Reference error angular not defined.

I m somehow missing out on some basic detail. It would be great if someone could give me some directions here

Answer

Replace

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular-resource.min.js"></script>

line with

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular-resource.min.js"></script>

Because its not getting library which is required by ngResource.

AND

Include this line in the beggining

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