텍스트 상자의 입력 값을 수정하는 간단한 각도 2 지시문이 있습니다. Model-Driven 형식 접근 방식을 사용하고 있습니다.각도 2 입력 지시문 수정 양식 제어 값
@Directive({
selector: '[appUpperCase]'
})
export class UpperCaseDirective{
constructor(private el: ElementRef, private control : NgControl) {
}
@HostListener('input',['$event']) onEvent($event){
console.log($event);
let upper = this.el.nativeElement.value.toUpperCase();
this.control.valueAccessor.writeValue(upper);
}
}
dom이 제대로 업데이트되지만 다른 모든 키 입력 후에 모델이 업데이트됩니다. plnkr
최고 :
여기 갈래의 plunker입니다 :
나는에 코드를 수정! 설명 해줘서 고마워. –
문자 위치는 어떻게됩니까? 키 누르기는 문자 위치를 입력 끝으로 보냅니다. – Skyler
@silntsod 템플릿 기반 양식과 함께 사용하는 방법을 알고 있습니까? ngModel 사용 – Vishal