I cannot find out how to use the required option in ng-select.
I have tried this:
<ng-select
#skills
required
[ngClass]="{ 'is-invalid': f.submitted && skills.invalid }"
[items]="options"
bindLabel="label" bindValue="value"
[multiple]="true" placeholder="Select Skills"
[(ngModel)]="registerUserData.skills"
name="skills[]">
</ng-select>
<div *ngIf="f.submitted && skills.invalid" class="invalid-feedback">
<div *ngIf="skills.errors.required">
Skills are required
</div>
</div>
but no luck there..
Any ideas?
You have to check on the value of
registerUserData.skills
if it is filled than show yourSkills are required
else, hide it.That is to say:
NOTE:
I do not know what
f.submitted
andskills.invalid
are, but assuming that they're related to the submit button event.You can achieve a better result using
ReactiveForms
.