angular is not defined Error

spandanchakrabo
ServiceNow Employee
ServiceNow Employee

Following : AngularJS: Developing Modern User Interfaces getting

Uncaught reference error : angular not defined:

/*! RESOURCE: service.sn-glideAjax */

angular.module('sn.glideAjax', []);

Any Clue how to resolve this issue.

I have following UI Script defined in Global scope:

service.sn-glideAjax

angular.module('sn.glideAjax', []);

angular.module('sn.glideAjax').service('GlideAjax', function($rootScope) {

  var glideAjax = window.GlideAjax;

  glideAjax.prototype.getJSON = function(callback) {

  this.getXMLAnswer(function(answer) {

  var answerJSON = JSON.parse(answer);

  callback(answerJSON);

  $rootScope.$apply();

  });

  };

  return glideAjax;

});

8 REPLIES 8

Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

Angular not defined pretty much means that the library isnt loaded.



just to test.. put this in your code:



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



just to see if that will work.. then it's how you load your ui script that isn't working.. Haven't done these labs myself, so not sure what they do in them.



//Göran


Thanks Goran, the Angular JS file is loaded from CDN , & I can see two way binding is working, but when it comes to add an dependency as mentioned in Lab to get data from Servicenow GlideAjax to Angular .. it is failing. I will debug more & see if I am missing anything else.


Manjul Katare
ServiceNow Employee
ServiceNow Employee

Hi Spandan,



if you are following : AngularJS: Developing Modern User Interfaces using AngularJS_Lab_Guide.pdf


Lets go one step back to your UI PAGE & UI SCRIPT. Can you check if you have these in place ?



find_real_file.png


find_real_file.png


find_real_file.png



According to the lab guide: If everything is in place you should see a blank page with a single input field. Whatever you type in that field should automatically print right next to it. This demonstrates a very basic Angular feature, using a UI Script to import Angular, and a UI Page to bring it all together.



If above UI page works for you, it should not show "Uncaught reference error : angular not defined" at all. If it does please check your UI script.



Hope this help!


-Manjul


Thanks Manjul, the Angular JS file is loaded from CDN , & I can see two way binding is working as your example , but when it comes to add an dependency as mentioned in Lab to get data from Servicenow GlideAjax to Angular .. it is failing. I will debug more & see if I am missing anything else.