I would like to get the max length of an input from a service (do an http call to get the value).
Is there any way to do it with calling the service only once?
<input type="text" [attr.maxLength]="getMaxLength()/>
Setting maxLength attribute value to a class property which value is set in contructor or ngOnInit will make it stop calling the service anymore
HTML:
<input type="text" [maxLength]="maxLength"/>
Typescript
maxLength: number;
.....
constructor(private myService: MyService){
this.maxLength = this.myService.getMaxLength();
}
DEMO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With