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.
5
  • call a function on change event, where you patch null to that input if the value entered is all 0s Commented Jul 31, 2018 at 7:23
  • what have you tried so far? Commented Jul 31, 2018 at 7:23
  • @Faisal tried patterns but it didn't work Commented Jul 31, 2018 at 7:27
  • @MohdTabishBaig I'm using change event and ill let you know if its worked or not Commented Jul 31, 2018 at 7:29
  • 1
    Maybe your answer is here? stackoverflow.com/questions/27916185/… Commented Jul 31, 2018 at 7:41

4 Answers 4

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

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.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.