2

I have the following select:

    <div class="form-group">
            <label class="col-md-4 control-label" for="activity">Activity</label>
            <div class="col-md-4">
                <select id="activity" name="activity" class="inputsvalues" ng-model="activitymodel.deptid" ng-change="getUsers(activitymodel.deptid)" ng-options="activity.DepartmentId as activity.ActivityDescription for activity in activities"></select>
            </div>
        </div>

The controller code:

    $scope.getUsers = function (id) {

    $http({
        method: 'GET',
        url: 'api/User/GetUsers/' + id,


    }).success(function (data, status, header) {
        $scope.users = data;

    }).error(function (data, status, headers, config) {
        $scope.status = status + ' ' + headers;
    });

}

The problem is that the ng-change function gets fired the first timeI select something. Second time onwards, it doesnt hit the controller. What could be wrong here?

Murali
  • 35
  • 7

1 Answers1

1

This is because.. for your code ng-model is same for each value in drop-down. Make ng-model unique for each option. Use $index to achieve this as one of the solutions.

Shah Rukh K
  • 559
  • 1
  • 5
  • 19