即使在使用$ apply后,$ scope也不会更新

时间:2017-08-24 11:49:47

标签: angularjs angularjs-scope anguarjs-digest-cycle angularjs-apply

我正在下面的视图中查看来自$ scope.saveSearchList的dropdoun列表:

<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>

在我的控制器中,我正在更新$ scope.saveSearchList,但它似乎并没有反映我的观点。我该如何解决这个问题?

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) {

                });
    }

1 个答案:

答案 0 :(得分:0)

我建议将第二个回调的“回复”重命名为其他内容。

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) {

      });
    }

此外,你有TalenPoolService.sucessNotify&lt; - 拼写错误,除非你有一个名为'sucessNotify'的方法。