Viveka
Viveka

Reputation: 237

trigger when dropdown option is selected angularjs

I have a dropdown list of countries. and when iam selecting a particular country my output should be filtered with details of only that country to be displayed following is my code but not working properly.

<label for="filtercountry" class="control-label col-xs-2">Filter By Country</label>

<div class="col-xs-2">

        <select class="form-control">
            <option value="None">-- Select --</option>
            <option ng-model="Tofilter.country" value="India" ng-change="changed()">India</option>
            <option ng-model="Tofilter.country" value="USA" ng-change="changed()">USA</option>
            <option ng-model="Tofilter.country" value="Pakistan" ng-change="changed()">Pakistan</option>
            <option ng-model="Tofilter.country" value="China" ng-change="changed()">China</option>
            <option ng-model="Tofilter.country" value="Australia" ng-change="changed()">Australia</option>
        </select>
    </div>`<ul id="result">

Name :{{x }}

`

Upvotes: 0

Views: 2495

Answers (3)

sylwester
sylwester

Reputation: 16508

<div class="col-xs-2">

        <select class="form-control" ng-change="changed()" ng-model="Tofilter.country" >
            <option value="None">-- Select --</option>
            <option value="India" >India</option>
            <option value="USA" >USA</option>
            <option value="Pakistan" >Pakistan</option>
            <option value="China" >China</option>
            <option value="Australia" >Australia</option>
        </select>
    </div>

Upvotes: 0

t0mpl
t0mpl

Reputation: 5025

it's not necessary to put your model in all option, put it in select

<select class="form-control" ng-change="changed()" ng-model="Tofilter.country">

Upvotes: 0

Michael Kang
Michael Kang

Reputation: 52867

Put ng-change on the select element:

<select class="form-control" ng-change="changed()">

Upvotes: 1

Related Questions