search

Home  >  Q&A  >  body text

javascript - A question about ng-bind in angular

<p class="IFreshMode">
     <span ng-bind = "freezerDoorStatus"></span>
                   </p>

There is such a piece of code in the project. span is bound to freezerDoorStatus. Two of the values ​​are true and one is false. The class of p can be changed according to the boolean value, but true and false will always be displayed in the span. Is there any way to not display it or display it as a switch?

扔个三星炸死你扔个三星炸死你2743 days ago883

reply all(3)I'll reply

  • 大家讲道理

    大家讲道理2017-06-17 09:17:39

    I still don’t quite understand your specific needs. See if it helps you
    Use ng-show="isOpen" or ng-if="isOpen"
    Then the controller can assign the value of $Scope.isOpen to true or false

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-06-17 09:17:39

    ng-bind is equivalent to the replacement expression method {}, for example:
    <span ng-bind="someValue" ></span>
    is equivalent to
    <span>{ { someValue }}</span>

    If you need to control the style, you need to use ng-class, ng-style. If you need to control the display, use ng-if or ng-show, for example:
    <span ng-style=" { backgroundColor : yourCondition ? 'red' : 'yellow' }" ></span>

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-06-17 09:17:39

    The above describes the correct use of ng-bind, that is, <span ng-bind = "freezerDoorStatus"></span> is equivalent to <span>{{freezerDoorStatus}}</span>.
    But when setting the style You can use ng-style or ng-class to control whether the style is displayed based on the value of the variable (true/false).
    You can use<p ng-class="freezerDoorStatus ? IFreshMode : 'otherClass'"></p>or use ng-style, as follows<p ng-style="{'color':iconColor}"> ;</p>.
    You can go to angular official website https://docs.angularjs.org/ap... for detailed introduction.

    reply
    0
  • Cancelreply