mosh-hamedani / angular2-course

130 stars 97 forks source link

basicValidators.ts #2

Open greglim81 opened 8 years ago

greglim81 commented 8 years ago

Anyone managed to get the validators in user-form.component.html to work?

scheilch commented 8 years ago

Of course! The only thing you have to do is to get the control correctly - this still is wrong in the code of mosh!!!

In the template you have to replace the local variable #name anf get the control via the userForm.controls Array:

                <input [(ngModel)]="user.name" id="name" name="name" formControlName="name" type="text" class="form-control">
                <div *ngIf="userForm.controls.name.touched && userForm.controls.name.invalid" class="alert alert-danger">

The same for the others

greglim81 commented 8 years ago

Hi scheilch, do you think you can share your code? I think it would just be user-form.component.ts and user-form.component.ts right?

scheilch commented 8 years ago

I just Shared the snippet but Github don't Show it. Go ahead with accessing the userForm.controls.name instead of the local Variable in the html file. That should work for you.