简体   繁体   中英

Reactive forms Angular format input data

Hi I am new to Angular Reactive forms and have been working on trying to figure this out.

What I want to do is format the input data to uppercase:/

<input #stateInput matInput type="text" 
formControlName="state" 
[matAutocomplete]="autoState" maxlength="2"
(keyup)="stateInput.value.toUpperCase()" 
required>

I haven't been able to get this to work?

Any help is appreciated

Thanks

To achieve expected result , use below option

Issue: After changing input value to uppercase, it has to be reassigned to show in Input field

 <input type="text" [formControl]="state" #stateInput (keyup)="stateInput.value = stateInput.value.toUpperCase()" /> 

code sandbox for reference - https://codesandbox.io/s/6l9nk4k2zn

you can just simple use below code which will convert input to UpperCase instantly ,

oninput="this.value = this.value.toUpperCase()"

here is an example Example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM