Ngshow two parameters - Angularjs

Asked

Viewed 202 times

3

Hello all right? I hope so! I’m still kinda Noob on the angular and today I came across a doubt, I need to spend two Xpression in the ng-show of Angularjs, I need the same do the show or Hide and arrow a var do $Scope for 'null', example I tried to:

<div class="col-sm-3 form-group" ng-show="!objParametros.tipo; objParametros.status=''">
    <p>teste</p>
</div>

2 answers

4


Hello all right? A tip that can help is the following:

<div class="col-sm-3 form-group" ng-show="isShowSetNull()">
    <p>teste</p>
</div>

<script>
    function isShowSetNull(){
         if (!objParametros.tipo){
             objParametros.status = null;
             return true;
         }
         return false;
    }
</script>

The idea is this, you leave in the View controller the responsibility to display and change the value, and call the function in your View, I believe that so it is simpler to evolve the code. Remembering that ng-show expects a Boolean as input!

NOTE: I put between the script tag to make sense, but the idea is to leave the script inside the controller.

1

The ng-show expects a boolean value, ie, true or false then you should treat it as a logical expression:

<div class="col-sm-3 form-group" ng-show="!objParametros.tipo || objParametros.status=''">
    <p>teste</p>
</div>
  • 3

    It will not work as desired, because when the first condition is true the variable will not be fulfilled. What he wants is that displaying or showing the component the variable is set to empty.

  • Then in addition to doing ng-show you will have to do an on-click for a function

  • Another way would be to create a method that returns bool and arrow the variable. More importantly, this can impact memory stacking in the DOM, as Angularjs' two-way-databinding stacks watches in memory to do the dirty work. The best would be to use an event in changing the objParametros.tipo to set the variable.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.