Model driven form validation issue in Angular 2

Discussão em 'Angular' iniciado por Madasu K, Outubro 30, 2024.

  1. Madasu K

    Madasu K Guest

    In Angular 2, Model Driven Form is using a Form Builder.

    I have:

    ngOnInit() {
    this.user = this.fb.group({
    id: ['', [Validators.required, Validators.minLength(2)]],
    name: ['', [Validators.required, Validators.minLength(5)]]
    });

    this.user.get('id').valueChanges.subscribe(value => {
    alert("Change detected);
    });
    }


    and in HTML I have :

    <input type="text" formControlName="id" >


    But what happening is for every letter I change in text box the alert("Change detected"); is getting fired, instead after tabout only I need to call alert("Change detected"). I know in AngularJS to achieve this by using ng-model-options, but how to achieve the same in Angular 2?

    Continue reading...

Compartilhe esta Página