I have an input field which is mandatory in order to proceed to the next page can't figure out how to validate the input(Name) ...searched online and tried various things but to no avail...
Any help highly appreciated...
<form>
<div>
<div class="form-group" style="width:50%">
<label class="label label-info" for="Name">Enter Name:</label>
<input [(ngModel)]="Name" class="form-control" required type="text"
name="Name" id="Name" />
</div>
<button kendoButton id="btnSearch" [primary]="true"
(click)="redirect()">Next</button>
</div>
</form>
Pretty simple. I recommend making a model-driven form.
In your component:
In the template, we will replace
[(ngModel)]
withformControlName="name"
.For your Next
button
we will disable it when form is not valid:[disabled]='!myForm.valid'
.Also notice
[formGroup]='myForm'
part.