0

I want to extend one filter function which used to enable/disable a button.

I have an array and am receiving a variable (serviceVariable) from a service. I am looping through this array to check whether this service value is available or not. if match, then filter function should return true to disable a button.

But service takes some time to update this serviceVariable, so on page load it is not matching with any of array variables. but after few seconds am receiving the serviceVariable with value.

can we use watch here? so that when my serviceVariable get update, I can check with new value.

or any other way?

james jelo4kul
  • 839
  • 4
  • 17
Nic
  • 387
  • 2
  • 5
  • 16

1 Answers1

0

You should try invoking filter from javascript, means from controller or service in the service call response.

So the thing is you need to call your filter asynchronously (i.e after making service call) in your js file. So call your filter in your js file like the following syntax,

$scope.isButtonShown = $filter('filtername')(arg1,arg2); // return true or false from filter which would dynamically show or hide the button

Hope this helps

For references :

How to use a filter in a controller?

How to use a filter in javascript instead of the Html

Community
  • 1
  • 1
Gopinath Shiva
  • 3,822
  • 5
  • 25
  • 48