Skip to main content
1-Visitor
June 15, 2018
Solved

Call function on view is loaded

  • June 15, 2018
  • 1 reply
  • 4020 views

I will call a service automatically when a view is loaded. I try this via window.onload or document.onload but this will not work. How can I realized this?

Best answer by ClayHelberg

Yes, I'm sure, I use it all the time. But you have to define the function first before assigning it as a callback. So try this instead:

 

$scope.init = function(){
 console.log("bla");
};

angular.element(document).ready($scope.init);

1 reply

18-Opal
June 15, 2018

You can do this by adding something like this to each View's JS pane:

 

angular.element(document).ready($scope.storeInitialState);

 

Replace "$scope.storeInitialState" with the name of your function, and it should fire when the view is done loading.

drichter1-VisitorAuthor
1-Visitor
June 18, 2018

I add this to my code:

angular.element(document).ready($scope.init);

$scope.init = function(){
 console.log("bla");
};

 

and I get this in my console logs:

TypeError: a is not a function

Are your sure I can use angular stuff in TWX Studio?

18-Opal
June 18, 2018

Yes, I'm sure, I use it all the time. But you have to define the function first before assigning it as a callback. So try this instead:

 

$scope.init = function(){
 console.log("bla");
};

angular.element(document).ready($scope.init);