を使用してフォームを送信した後、値が最後に小文字を返す理由を誰かが見つけるのを手伝ってくれますか
import { FormGroup, FormControl, Validators } from '@angular/forms';
これが私のコードです
component.ts
import { Component, Directive, OnInit, OnDestroy} from '@angular/core';
import { FormGroup, FormControl, Validators } from '@angular/forms';
import {UppercaseDirective} from '../uppercase.directive';
@Component({ selector: 'app-storageentry',
templateUrl: './storageentry.component.html',
styleUrls: ['./storageentry.component.css']
})
export class StorageentryComponent implements OnInit, OnDestroy {
storageForm: FormGroup;
private initForm(){
let storageDescription: string;
//pass the formControl specified by '' to use in HTML
this.storageForm = new FormGroup({
description: new FormControl(storageDescription, Validators.required)
})
}
}
ngOnInit() {
this.initForm();
}
onSubmit(){
this.storageEntryService.addStorage(this.storageForm.value);
this.storageForm.reset();
}
uppercase.directives.ts
import { Directive, HostListener, Renderer, ElementRef } from '@angular/core';
@Directive({
selector: '[uppercase]'
})
export class UppercaseDirective{
constructor(
private renderer: Renderer,
private el: ElementRef
){}
@HostListener('input') input() {
this.el.nativeElement.value=this.el.nativeElement.value.toUpperCase();}
}
component.html
<div class="form-group input-holder">
<label class="col-lg-2">Description</label>
<div class="col-lg-4">
<small [ngClass]="{'prompterror': storageForm.controls.description.valid || storageForm.controls.description.pristine}">
*required
</small>
<input type="text" class="input-field" placeholder="Description" formControlName="description" uppercase>
</div>
</div>