Reputation: 277
I have a form in angular and I want to use value of form "Validators.minLength" in html input tag.
I want Know is any way to use directly from form validator in html;
sample: [maxLength]="form.get('zipCode').validators('maxLength)"
My ts code is:
zipCode: [ '', [
Validators.required,
Validators.maxLength(10),
number,
],
and html is:
<input type="tel"
formControlName="zipCode"
[maxLength]="10" // here I want insert dynamic number from ts file
placeholder="insert your zip code">
tanks for your helping.
Upvotes: 4
Views: 718
Reputation: 5442
TS:
public maxZipCodeLength: number = 10;
HTML:
<input type="tel" formControlName="zipCode" [maxlength]="maxZipCodeLength" />
This should be enough.
Upvotes: 1
Reputation: 910
TS
this.maxLength=10;
zipCode: [ '', [
Validators.required,
Validators.maxLength(this.maxLength),
number,
],
HTML
<input type="tel" formControlName="zipCode" placeholder="insert your zip code">
Upvotes: 2