0
<form>
    <div class="form-group">
        <label for="sel1 primary"></label>
        <select class="form-control" id="sel1">
            <option *ngFor="let group of instanceList"(click)="change_group(group.name)" > <a href="#"> {{group.name}}</a> 
            </option>
        </select>
    </div>
</form>

Sorry for bad indentation. Instancelist list is the array of object contain, id, name, groupnumber. I want to get the value of selected option in my calling method and want to display it in console.

function change_group(groupname){
     this.change_to=groupname;
     console.log(change_to);
}

The problem is, the given function not even call upon selecting value in dropdown.

2 Answers 2

1

Why not leave the option tags alone and just subscribe to the selection changed event in the <select> tag

<select class="form-control" id="sel1" (change)="onGroupChange($event)">
Sign up to request clarification or add additional context in comments.

Comments

1

(click) on <option> is usually not how to do it.

Use instead ngModel

<select class="form-control" id="sel1" ngModel (ngModelChange)="change_group($event)">
  <option *ngFor="let group of instanceList" [ngValue]="group"> <a href="#"> {{group.name}}</a> 
        </option>

2 Comments

Template parse errors: Can't bind to 'ngValue' since it isn't a known property of 'option'. ("ge_group($event)"> Thanks for answering, actually this error occur
You need to add the 'FormsModule` to imports: [...]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.