selma
selma

Reputation: 77

ng-change in select not working

I'm trying to update a list2 from a list1, and i used ng-change for that.

My app is fully configured and the controller for the html page is well setted.

The only thing that when i select the elemt from my first list1 the method updateList2 never invocked

<label>NameLIst1</label>
<select ng-model="idLIST1" 
        ng-change="updateList2(idLIST1)"
        ng-options="elt.id as elt.name for elt in list1">

        <option  value="">select one</option>
</select>

<label>Name LIST 2</label>
<select  ng-model="idLIST2"                 
        ng-options="elt.id as id.name for elt in list2">

        <option  value="">select one</option>
</select>


$scope.updateList2 = function(id){
alert("id ="+id);
}

Upvotes: 0

Views: 2646

Answers (1)

kushal shah
kushal shah

Reputation: 863

I have code which are written in below ,try this it's work fine,also work with param, but you don't need to pass param in methods

<div class="container" ng-controller="TestController">
    <label>NameLIst1</label>
    <select ng-model="idLIST1"
            ng-change="updateList2(idLIST1)"
            ng-options="elt.id as elt.name for elt in list1">

        <option value="">select one</option>
    </select>

    <label>Name LIST 2</label>
    <select ng-model="idLIST2"
            ng-options="elt.id as id.name for elt in list2">

        <option value="">select one</option>
    </select>
</div>

var app = angular.module("test", ["ngRoute"])
        .controller("TestController", ['$scope', function ($scope) {
            $scope.list1 = [
               { id: 1, name: 'data1' },
               { id: 2, name: 'data2' },
               { id: 3, name: 'data3' },
               { id: 4, name: 'data4' },
            ];
            $scope.updateList2 = function (id) {
                alert("id =" + id);
            }
        }
        ]);

Upvotes: 1

Related Questions