angularjsangularjs-scopeangularjs-digestangularjs-apply

$scope not updating even after using $apply


I am redering a dropdoun list from $scope.saveSearchList in my view below:

<div class="form-group" ng-controller="TalentPoolController">
  <md-input-container ng-init="SchoolSavedSearches(39424,2,true)"
    class="md-block" style="margin:0 !important;">
    <md-select ng-model="selectedSavedsearch"
      placeholder="Select a Saved Search" id="Md-select2">
      <md-option ng-value="s" ng-repeat="s in savedSearchList">{{s.title}}</md-option>
    </md-select>                                          
  </md-input-container>
</div>

In my controller I am updating the $scope.saveSearchList but it doesn't seems to be reflecting my view. How do i resolve this please?

TalentPoolService.insertSaveSearch(pvarrData)
  .then(function successCallback(response) {

  if (response.data.status == true) {
    TalentPoolService.sucessNotify("Saved Search have been created successfully.", 5000, 640);

            TalentPoolService.GetSchoolSavedSearches(39424, 2, true)
                .then(function successCallback(schoolResponse) {
                    $scope.savedSearchList = schoolResponse.data;
                    $scope.$apply();
                }, function errorCallback(schoolResponse) {

                });
    }

Solution

  • I would suggest renaming your second callback's 'response' to something else.

    TalentPoolService.insertSaveSearch(pvarrData)
      .then(function successCallback(response) {
    
      if (response.data.status == true) {
        TalentPoolService.sucessNotify("Saved Search have been created successfully.", 5000, 640);
    
        TalentPoolService.GetSchoolSavedSearches(39424, 2, true)
          .then(function successCallback(schoolResponse) {
            $scope.savedSearchList = schoolResponse.data;
            $scope.$apply();
          }, function errorCallback(response) {
    
          });
        }
    

    Also, you have TalenPoolService.sucessNotify <- spelled wrong, unless you have a method called 'sucessNotify'.