Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Extension Dev: Call function once when custom property changes

Hi,

Let's say I have an extension, with a custom property, 'app'.

When the value of 'app' changes, I want to call a function once and once only. 

I'm using AngularJS in my extension, and the function is relatively expensive (so I don't want to keep calling it in paint() or resize() or call it directly from the template.

My current solution means that the code is only called once when the extension is loaded, and any changes to the property mean a refresh is required to update things - not an ideal situation.

thanks,

Shane.

1 Solution

Accepted Solutions
Not applicable
Author

Hi,

I managed to solve it by doing this:

$scope.$watch("$parent.$parent.editmode", function(newValue, oldValue) {

  // call function

}, true);

Regards,

Shane.

View solution in original post

5 Replies
Not applicable
Author

Alternatively,

call a function when the extension exits edit mode.

jvitantonio
Luminary Alumni
Luminary Alumni

Hi Shane, can you share the bit of code that calls this function? It will make it easier for us to help with an example.

Without knowing your situation, I would do something life this:

var executeOnce = false;

var myFunction = function() {

    if(!executeOnce)

  {

               do something...

  executeOnce = true;

  }

};

JV

Not applicable
Author

Hi,

thanks for getting back to me.   I don't want it to call once for its lifetime, I want it to call once after a property has changed.  In fact, my first reply is probably more accurate, I want to call the function when Sense 'exits' edit mode

My function basically calls getAppList(...) and does several subsequent things that I don't want to be happening more than I need.  The getAppList return then uses the property panel's apps collection (there are properties for 'app1', 'app2', 'app3', 'app4' and 'app5') to return and show information about the apps.

When the extension loads, the code fires and things work nicely.  But when somebody goes into the property panel and modifies something, the code doesn't fire again.

I hope that makes sense,

Shane.

jvitantonio
Luminary Alumni
Luminary Alumni

Can you please post the code of when a property changes and the definition of those properties?

JV

Not applicable
Author

Hi,

I managed to solve it by doing this:

$scope.$watch("$parent.$parent.editmode", function(newValue, oldValue) {

  // call function

}, true);

Regards,

Shane.