Is there any preferred way when selecting validation using
myForm.controls['name'].valid
myForm.get('name').valid
as both seems to be only syntactically different but achieving the same goal.
<label>Name
<input type="text" formControlName="name">
</label>
<div class="alert" *ngIf="!myForm.controls['name'].valid && myForm.controls['name'].touched">
{{ titleAlert }}
</div>
Same as
<div class="alert" *ngIf="!myForm.get('name').valid && myForm.get('name').touched">
{{ titleAlert }}
</div>
From what I checked in the code, get
has this code:
AbstractControl.prototype.get = function (path) { return _find(this, path, '.'); };
I have just started Angular, so an expert opinion would be appreciated.