search

Home  >  Q&A  >  body text

angular.js - angular's-if

How to set multiple conditions in ng-if? For example, ng-if="code == 2 ‖ 3" is it possible?

世界只因有你世界只因有你2811 days ago659

reply all(3)I'll reply

  • 巴扎黑

    巴扎黑2017-05-15 17:02:53

    ......
    This has nothing to do with angular, let's take a look at javascript first.

    code === 2 || code === 3

    reply
    0
  • 怪我咯

    怪我咯2017-05-15 17:02:53

    ng-if is followed by a normal js statement. If your intention is to compare whether code is equal to 2||3, then write o like this. k
    If your intention is to determine whether code is equal to 2 or equal to 3, that is

    code === 2 || code === 3
    

    Of course, the code must first be in the scope of angular.

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-15 17:02:53

    {true:THIS, false:THAT}[CONDITION]
    <p ng-repeater="item in items">

    <p>{{item.description}}</p>
    <p>{{ {true:'available', false:'oh no, you don't have it'}[isExists(item)] }}</p>

    </p>

    方法二:
    <p ng-repeater="item in items">

        <p>{{item.description}}</p>
        <p ng-switch on="isExists(item)">
            <span ng-switch-when="true">Available</span>
            <span ng-switch-default>oh no, you don't have it</span>
        </p>
    </p>
    
    方法三:
    <p ng-repeater="item in items">
        <p>{{item.description}}</p>
        <p ng-show="isExists(item)">available</p>
        <p ng-show="!isExists(item)">oh no, you don't have it</p>
    </p>

    reply
    0
  • Cancelreply