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

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

how can I refer the widget property in multiple view environment?

성장_10243899
12-Amethyst

how can I refer the widget property in multiple view environment?

Hi, all

 

I want to refer the widget property value in multiple view.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

$scope.test = function(){
$scope.app.view['Home'].wdg['label-1']['text'] = "test";
}

 

I coded like upper to set the property in other view.

but I got the error log like below.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Error evaluating button-1 click JS: test();

TypeError: Cannot read properties of undefined (reading 'wdg')

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 

why I am not able to set the property value in other view?

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @성장_10243899

so far my knowledge the widget data is accessible only in the context of the active view. So that when the view is not loaded you could not set properties. Also all property which are set , they will be lost when the view unloaded e.g. by exit or loading of another view.

So, I think there are some  different techniques to take care about a permanent setting of variables and properties at run time. The simples is to have variables which are persistent for different views  is to use an application parameter which could be set any time e.g. by property link or javascript code. So the application parameter could be linked to a property of the specific view - so means changing the app parameter will change the property when the view is loaded. This is some kind of static link

Another option is to use  some 

 

 scope.$on('$ionicView.afterEnter', function() {
//your javascript here
})

 

where you can do some setup task when a view is loaded. So you can read for some saved variables globally in the app parameters or in the global scope $rootScope and set them to the widgets of particular view when the view is loaded. also windows context could be used e.g. window.localStorage which could save permanent values during a project is opened (see also post )

 

window.localStorage.clickcount = 1;

 

 

View solution in original post

3 REPLIES 3

Hi @성장_10243899

so far my knowledge the widget data is accessible only in the context of the active view. So that when the view is not loaded you could not set properties. Also all property which are set , they will be lost when the view unloaded e.g. by exit or loading of another view.

So, I think there are some  different techniques to take care about a permanent setting of variables and properties at run time. The simples is to have variables which are persistent for different views  is to use an application parameter which could be set any time e.g. by property link or javascript code. So the application parameter could be linked to a property of the specific view - so means changing the app parameter will change the property when the view is loaded. This is some kind of static link

Another option is to use  some 

 

 scope.$on('$ionicView.afterEnter', function() {
//your javascript here
})

 

where you can do some setup task when a view is loaded. So you can read for some saved variables globally in the app parameters or in the global scope $rootScope and set them to the widgets of particular view when the view is loaded. also windows context could be used e.g. window.localStorage which could save permanent values during a project is opened (see also post )

 

window.localStorage.clickcount = 1;

 

 

so back to your example and the app parameter

e.g. create an app parameter 2023-02-08_16-01-38.jpg

you can create a binding form this app parameter to different widget properties.

Then when you change the parameter value this will change all property in the active view which are associated with this app parameter.  When another view is loaded and it use a binding to this parameter this should update the value , when there is existing  binding form parameter to the property.

Then to sett all values having binding from this parameter you should do some thing like this:

 

$scope.test = function(){
//$scope.app.view['Home'].wdg['label-1']['text'] = "test";
//instead of this above set the app parameter which has binding to
// text property of label-1 widget
$scope.app.params.myMultiViewTEXT="test";

$scope.app.params['myMultiViewTEXT']="test";
// or another valid usage, syntax which will accept space in paramName
//e.g bla bla  $scope.app.params['bla bla']="test";
//$scope.app.params.bla bla="test";
// will not work in this case
}

 

 

Hi, RolandRaytchev

 

Thanks for your kind explanation.

I resolved this problem with your explanation.

Thanks!

Top Tags