I've encountered an issue with ng-change in a select not triggering when I update the ng-model parameter within my promise.then function. Here's my select code:
<select ng-model="currentReport"
ng-options="rpt.ReportDisp for rpt in availableReports"
ng-change="updateDependent()"></select>
My 'availableReports' array is fetched using a $http call in my service. After the call completes, I want to ensure the first entry is selected and perform the following code:
webServices.getReports(user, menu1, menu2)
.then(function (result) {
$scope.availableReports = result.data.d;
$scope.currentReport = $scope.availableReports[0];
}
This code successfully sets the select to the 1st report, but the ng-change event does not trigger the 'updateDependent()' function.
I also attempted to directly call the 'updateDependent()' function within the .then block like this, however, $scope.currentReport was undefined when the function was invoked:
webServices.getReports(user, menu1, menu2)
.then(function (result) {
$scope.availableReports = result.data.d;
$scope.currentReport = $scope.availableReports[0];
updateDependent();
}
Does anyone understand what might be causing this issue?
Update: Problem Solved!
The problem was that the 'updateDependent' function was defined as '$scope.updateDependent()', so I needed to update the reference in the associated .then function to '$scope.updateDependent()'.