You can simply make the input type = number and set min value to 0 .
Regards
Haris

On Mon, 18 May 2020 at 11:09 PM, Maureen Moore <makam...@gmail.com> wrote:

> I'm trying to make a number input that is for only positive numbers. I
> have the following html:
>
> <button class="minus-btn" (click)="minus()" type="button" name="button">
> <img src="../assets/images/minus.svg" alt="minus" />
> </button>
> <input ng-pattern="^(0|\+?[1-9]\d*)$" class="num" name="quantity"
> [value]="quantity" type="number" min="0">
> <button class="plus-btn" (click)="plus()" type="button" name="button">
> <img src="../assets/images/plus.svg" alt="plus" /></button>
>
> As you can see, I've implemented ng-pattern and min value but neither one
> works. In the controller:
>
> quantity: number=1;
> i=1;
>
> plus(){
> this.i++;
> this.quantity=this.i;
> }
>
> minus(){
> this.i--;
> this.quantity=this.i;
> }
>
> When I add the following to the controller, I get the error " Property
> 'match' does not exist on type 'number'"
>
> this.quantity.match(/^(0|\+?[1-9]\d*)$/g);
>
> --
> You received this message because you are subscribed to the Google Groups
> "Angular and AngularJS discussion" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to angular+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/angular/62bb9684-1ea2-4527-acb4-70367e38aa63%40googlegroups.com
> <https://groups.google.com/d/msgid/angular/62bb9684-1ea2-4527-acb4-70367e38aa63%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/angular/CAJVNGfUrMNECm7Hoj0MbcSCPO2TkyZO8pktzL6S%3Dz7C_m567Yg%40mail.gmail.com.

Reply via email to