Can I use ngIf in the modal box in angular2?

this is the code:

      <div class="col-7">
        <label>:</label>
        <input type="number" class="form-control" placeholder="" (keyup)="inputCoinQty()" required [min]="0.001">
      </div>
      <div *ngIf="inputCoinQty()" class="text-center">
        <p class="my-3">:{{values}}

<img src="/assets/images/pay.png" class="avatar-xxl"> <p class="my-3">

</div>

what you want to achieve: display the class text-center when the user types
this is in the modal of angular2, not in component
clipboard.png


turns out to be an expression, not a method, in * ngif.


* ngif can also be a method. The method has the return value of boolen. You can try it.


* ngIf= "expression" is followed by an expression, which means you can write methods, such as * ngIf=someFunc () . As long as the return value of someFunc () in Component can be displayed / implicitly converted to a value of type boolean.


you can listen to the change event of input, control the flage, in the change event, and then that div can use ngClass

ngClass the first parameter is the class name, the second parameter is the Boolean value, if it is true, add the class of the first parameter

when the user has input, flag is true. False

if the value is cleared
<div [ngClass]="{'text-center':flag}"><div>
Menu