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

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

Call function on view is loaded

drichter
14-Alexandrite

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?

1 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
14-Alexandrite
(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
14-Alexandrite
(To:ClayHelberg)

Thx that works 🙂

Top Tags