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

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

Order of execution

cmodin
8-Gravel

Order of execution

I've been trying to reference a widget the first time a view is opened, but when I do the console logs it as undefined. For a view, are widgets defined after the first time the js runs? Thank you

ACCEPTED SOLUTION

Accepted Solutions

Hi @cmodin ,

 

I think the problem is here as your correct mentioned in your post  is that when you try to use references of object they are no loaded yet.

So the solution is simple . You can call you code in a function of some events

For referring to 2d widget you can use the $ionicView.afterEnter event. When this event is called all 2d widget are already loaded and could be accessed by javaScript

Example:

 

$scope.$on('$ionicView.afterEnter', function()  {
   $scope.view.wdg['image-1']['imgsrc']="app/resources/Default/vu_fuel-pump.svg"; 
 });

For 3d Widget (model widgets and modelitem widgets)  you can use the modelLoaded event

example

$rootScope.$on('modelLoaded', function() {
  
    $scope.view.wdg['modelItem-door-aus']['forceHidden'] = true;
    $scope.view.wdg['modelItem-door-aus']['visible'] = true;
    $scope.view.wdg['slider-2']['value']=0;
    $scope.view.wdg['modelItem-door-aus']['forceHidden'] = false;
...
})

Of course there is also possible to use other events but also the $timeout() service. So, you can call a function with delay, but this is something where we are not sure how long  should be the delay and in some cases because hanging of device or loading of  more complex model this could fails.

View solution in original post

1 REPLY 1

Hi @cmodin ,

 

I think the problem is here as your correct mentioned in your post  is that when you try to use references of object they are no loaded yet.

So the solution is simple . You can call you code in a function of some events

For referring to 2d widget you can use the $ionicView.afterEnter event. When this event is called all 2d widget are already loaded and could be accessed by javaScript

Example:

 

$scope.$on('$ionicView.afterEnter', function()  {
   $scope.view.wdg['image-1']['imgsrc']="app/resources/Default/vu_fuel-pump.svg"; 
 });

For 3d Widget (model widgets and modelitem widgets)  you can use the modelLoaded event

example

$rootScope.$on('modelLoaded', function() {
  
    $scope.view.wdg['modelItem-door-aus']['forceHidden'] = true;
    $scope.view.wdg['modelItem-door-aus']['visible'] = true;
    $scope.view.wdg['slider-2']['value']=0;
    $scope.view.wdg['modelItem-door-aus']['forceHidden'] = false;
...
})

Of course there is also possible to use other events but also the $timeout() service. So, you can call a function with delay, but this is something where we are not sure how long  should be the delay and in some cases because hanging of device or loading of  more complex model this could fails.

Announcements

Top Tags