Validating a selectbox from within the template in Angular


February 2019


7 time


I would like to access to the value of a dropdown and if the value is "-1" i would like to give a message to the user. I know i can use a variable with 2 way binding and check its value but i want to do it only using the template. I am trying to do something like below.

<select #selectAccessor name="testSelect" [ngModel]="testUnit.field" class="form-control" style="width: 80 px">
    <option value="-1">Seciniz</option>
    <option value="Option 1">Option 1</option>
    <option value="Option 2">Option 2</option>
<!-- Below Part is not working -->
<div *ngIf="selectAccessor.value='-1'">Please make a selection</div>

0 answers