Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Trigger event when clicked outside the input element in service portal

aamir1
Mega Expert

Hello All,

I am trying to show and hide a div element based on click event on an element in another widget.

I am able to show the element using the $broadcast and $on but I am not sure how can we hide the element if we click outside the input element.

Please help how can we resolve this.

2 REPLIES 2

Anil Shewale
Mega Guru

Hi

For implement the same mechanism, directives ng-show and ng-hide are also used.

find_real_file.png

Differences between ng-if and ng-show(ng-hide):

ng-show (and its sibling ng-hide) toggle the appearance of the element by adding the CSS display: none style.

ng-if, on the other hand, actually removes the element from the DOM when the condition is false and only adds the element back once the condition turns true.

The best practice is to use ng-if because ng-show spends more time.

 

If it help mark helpful or correct 

Thanks and regards

Anil

Hello Anil,

 

But how can we achieve the false condition? I am already using ng-if to show when the flag is true, but how to make the flag false when the user clicks outside the input element?