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

Hi Spandan,



are you loading sn.glideAjax in your main app module? if not then it will give you an error. and before using GlideAjax service in any controller make sure you inject it in that controller.



i hope this helps.


My UI Page:


find_real_file.png


My UI Scripts where sn.GlideAjax is added:


find_real_file.png


SN.glideAjax   UI Script:


find_real_file.png



Error in Console:


find_real_file.png



Please advise.


everything looks fine.



can you load your scripts like this.


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



  <script>



  <g2:evaluate var="jvar_stamp">


        var gr = new GlideRecord('sys_ui_script');  


        gr.get("cf4ad1154f6452008c8a7bb28110c725");   //sysid of your ui script


        gr.getValue('sys_updated_on');


    </g2:evaluate>  


    <g:requires name="yourapp.youruiscript.jsdbx" params="cache=$[jvar_stamp]" />




make sure you have not made anychanges in sn-glideAjax script. if you have then it will not reflect as it will be cached by the browser.


ciaranm
Kilo Explorer

I had the same issue initially, big guy.



Just add the script in the same app scope you're working on and make it accessible to all scopes.


Make sure to include your scope prefix when sourcing it from your UI page:



<script>