cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

Call function on view is loaded

drichter
15-Moonstone

Call function on view is loaded

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?

ACCEPTED SOLUTION

Accepted Solutions

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);

View solution in original post

5 REPLIES 5

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.

drichter
15-Moonstone
(To:ClayHelberg)

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?

drichter

try this .....

 

angular.element(document).ready(function () {
$scope.init();
});

 

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

 

I hope to be proved helpful.

bye

Giuseppe

 

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);
drichter
15-Moonstone
(To:ClayHelberg)

Thx that works 🙂

Announcements

Top Tags