1
<input type="text" class="form-control"
                   id="transactionAmount"
                   maxlength="10"
                   OnlyNumber="true" 
                   [(ngModel)]="userBalance.transactionAmount" 
                   name="transactionAmount"
                   placeholder="Amount"
                   required
                   #transactionAmount="ngModel">
  1. Here I have to hide zero amount while user entering the values.
  2. If he enters all zero's then only we have to hide not in cases like 20,30,100 etc...
  3. I'm using Angular 2.
Daniel
  • 10,641
  • 12
  • 47
  • 85
Liyakhat Ali Sheikh
  • 163
  • 1
  • 5
  • 17

4 Answers4

2
<input type="text" class="form-control"
               id="transactionAmount"
               maxlength="10"
               OnlyNumber="true" 
               [(ngModel)]="userBalance.transactionAmount" 
               name="transactionAmount"
               placeholder="Amount"
               required
               #transactionAmount="ngModel"
               (keyup)="hideZero()>

Added This keyUp event in Html and in .ts added below code

hideZero(){
if(this.userBalance.transactionAmount === '0' ){
    this.userBalance.transactionAmount = '';
}

}

Working Absolutely fine

Liyakhat Ali Sheikh
  • 163
  • 1
  • 5
  • 17
0

Try using (ngModelChange) event which will trigger when user types values. By using regex, you can remove the last zero value and update the DOM. Hope this helps.

Suresh Kumar Ariya
  • 9,516
  • 1
  • 18
  • 27
0

/* In your ts */
validateNumber(value: String) {
 userBalance.transactionAmount = value && value.replace(/(?:0*)(\d*)/g, (_,value1) => {
 return value1;
})
}
<input (input)="validateNumber($event)">
Black Mamba
  • 13,632
  • 6
  • 82
  • 105
0

Angular 0 value don't display

<span *ngIf="!pro.model === '0'">{{ pro.model }}</span>

Like this, When model value is zero that time don't display model value. If model value is not zero that time show model value in your html pages.

Sarfaroj
  • 61
  • 1
  • 4