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

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

Vuforia Studio Javascript snippet to get all widgets in current view

O.R.Natale
7-Bedrock

Vuforia Studio Javascript snippet to get all widgets in current view

Hello,

 

How do I get a reference to all widgets in current view?

I know that I can get a reference to all widgets for a specific view as follows:

 

 

// Get a reference to all widget for the Home view
var wdgs = $scope.app.view.Home.wdg;

 

 

However, to generalize the code, I would like to get the same reference but to the active (current) view.

 

Many thanks!
Riccardo,

 

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @O.R.Natale ,

I am not sure what is the application case so that you need extra treatments because when you load a view you can use some global variables which could be a set of  all widgets for the specific view - so which is loaded. Possibly you tried this before everty thing was loaded yet. So that you need to use the view enter event - Something like this:

 $scope.$on("$ionicView.afterEnter", function (event) {
$scope.myWidgets=$scope.app.view.Home.wdg;
})//this could be added to the home view
/// respectivively 
 $scope.$on("$ionicView.afterEnter", function (event) {
$scope.myWidgets=$scope.app.view.TEST.wdg;
})//this could be added to the TEST view etc.

alternatively you could create for each view some code which set the current loaded view name to an application parameter

 $scope.$on("$ionicView.afterEnter", function (event) {
  $scope.app.params.PAR_VIEW=Object.keys(event.targetScope.app.view)[0])
//will set  the current loaded view tot the app parameter PAR_VIEW
})

 you can add this sniped of code to each view.  and later you can do something like this

var wdgs = $scope.app[$scope.app.params.PAR_VIEW].wdg;

which could be get by much more easily in a way like calling:

var wdgs=$scope.view.wdg;

 

 

View solution in original post

2 REPLIES 2

Hi @O.R.Natale ,

I am not sure what is the application case so that you need extra treatments because when you load a view you can use some global variables which could be a set of  all widgets for the specific view - so which is loaded. Possibly you tried this before everty thing was loaded yet. So that you need to use the view enter event - Something like this:

 $scope.$on("$ionicView.afterEnter", function (event) {
$scope.myWidgets=$scope.app.view.Home.wdg;
})//this could be added to the home view
/// respectivively 
 $scope.$on("$ionicView.afterEnter", function (event) {
$scope.myWidgets=$scope.app.view.TEST.wdg;
})//this could be added to the TEST view etc.

alternatively you could create for each view some code which set the current loaded view name to an application parameter

 $scope.$on("$ionicView.afterEnter", function (event) {
  $scope.app.params.PAR_VIEW=Object.keys(event.targetScope.app.view)[0])
//will set  the current loaded view tot the app parameter PAR_VIEW
})

 you can add this sniped of code to each view.  and later you can do something like this

var wdgs = $scope.app[$scope.app.params.PAR_VIEW].wdg;

which could be get by much more easily in a way like calling:

var wdgs=$scope.view.wdg;

 

 

Hello @RolandRaytchev ,

 

I'm trying to build a very small and simple library that implements experience localization by cycling all widgets in a view and then changing the "Text" property, if any, according to the locale set as an app parameter at the beginning of the app life cycle.

 

It appears that

var wdgs=$scope.view.wdg;

 does the trick in the simplest way! 

 

Thanks,

Riccardo.

Top Tags