Skip to main content
1-Visitor
October 26, 2021
Solved

Call a function on changed value event

  • October 26, 2021
  • 1 reply
  • 1513 views

Hi everyone,

I would like to call a function on changed value event. How can I do this?

The value to be monitored is in a label, it is used to indicate the step of my animation. The property text of label is binded to CurrentStep of my 3D Model which contains animation sequences.

Thanks,

 

Maxime.

Best answer by RolandRaytchev

Hello @MaximeDid ,

one possible option to define a change value event and to call an action when a widget property will chang   , is to use  the $watch angular construct / defintion in  javascript e.g. in the Home.js -> some code like this:

 

 $scope.$watch("view.wdg['label-1']['text']", 
 function (newValue, oldValue, scope) {
console.log("Old Value -befor it was changed =" + oldValue); 
//! it could be undefined first time called
console.log("new Value -after it was changed =" + newValue); 
//prints the current $scope (copy) object passed to the $watch construct
// pay attention it has no $ !
console.warn(scope);// the scope variable passed to the function
// this is the same as $scope but has not the $-char
})

 

1 reply

21-Topaz I
October 26, 2021

Hello @MaximeDid ,

one possible option to define a change value event and to call an action when a widget property will chang   , is to use  the $watch angular construct / defintion in  javascript e.g. in the Home.js -> some code like this:

 

 $scope.$watch("view.wdg['label-1']['text']", 
 function (newValue, oldValue, scope) {
console.log("Old Value -befor it was changed =" + oldValue); 
//! it could be undefined first time called
console.log("new Value -after it was changed =" + newValue); 
//prints the current $scope (copy) object passed to the $watch construct
// pay attention it has no $ !
console.warn(scope);// the scope variable passed to the function
// this is the same as $scope but has not the $-char
})

 

MaximeDid1-VisitorAuthor
1-Visitor
October 27, 2021

Hi @RolandRaytchev ,

 

It works very well, thank you!