In Service Portal, How to Use AngularJS services rather than window objects?

vspk
Giga Expert

Hi All,

 

ServiceNow ran health scan reports and we were suggested to replace window objects with Angular JS in the Service Portal wisgets.

We have few 'client controller' script lines as below:

var url = this.parent.location.href;

var popup = window.open (url);

window.setTimeout(function())

 

 

Would anyone please suggest how to replace these window objects with Angular JS?

 

Regards,

Venkata

1 REPLY 1

Varsha Jadhav1
Giga Expert

hi

 

In your Client Controller field in the widget, just make sure you pass in the $window and $timeout parameters so you have access to them...

 

 

 

function ($scope, $window, $timeout) {

 

  var c = this;

 

 

 

//

 

// ... put your code in here for your widget

 

//

 

 

 

  $timeout(function() {

 

      $window.location.href="the url to redirect to";

 

  }, 10000, false);

 

}

 

 

 

 

 

However, this simple code will redirect at 10 seconds regardless of what the user is doing so if they have half of their stuff filled out it will redirect while they may be in mid key-stroke so you probably want to add some intelligence into your widget and how it interacts before you pull the trigger on the rewrite.