Reputation: 161
I want to limit the input maximum number.
data = [
{
qq:[30]
},
{
qq:[100]
}
<div *ngFor="let data of data">
max{{data.qq[0]}}
<input type="number" id="test" oninput="if(value > data.qq[0]) value = data.qq[0]">
</div>
Seem make sense.but have a error "data is not defined"
how to fix it.
I try ngModel but effect is not very good. After exceeding the maximum value, the user can continue to input.
https://stackblitz.com/edit/angular-s5uwe6?file=src%2Fapp%2Fapp.component.ts
Upvotes: 12
Views: 26060
Reputation: 942
You can use keyup method in HTML and send $event.target.value as input to your required method.
<input (keyup)="filterData($event.target.value)">
filterData(e){
console.log(e);
}
Upvotes: 1
Reputation: 161
If someone is still interested, you can use (input)
<input type="number" id="test" (input)="yourFunction()">
Upvotes: 16
Reputation: 24434
simply you can use max attribute
<input type="number" id="test" [max]="data.qq[0]">
Another way something like this
<input type="number" id="test" #v (change)="+v.value > data.qq[0]? v.value = data.qq[0]:0">
Upvotes: 0
Reputation: 7289
oninput
event in angular, use ngModel
oninput
will not work anywayUpvotes: -1