2016-11-27 69 views
0

我有一個關於範圍和承諾的小問題。 我在promise函數外聲明瞭wiz_ids,並且我希望在promise解決後再次訪問它。 我試圖使用bind()但沒有運氣。範圍訪問,當承諾在Angular UI中解決時

這是我的狀態:

state: 'wizard', 
config: { 

    url: '/wizard', 
    templateUrl: 'app/partners/wizard/wizard.html', 
    controller: 'WizardController', 
    controllerAs: 'vm', 
    redirectTo: 'wizard.step1', 
    resolve: { 
     /* @ngInject */ 
     promiseData: ['$window', '$location', 'WizardDataService', function ($window, $location, WizardDataService) { 
       var wiz_ids = { 
        'wiz_install_id': $location.search().install_id, 
        'wiz_instance_id': $location.search().instance_id 
       }; 

       return WizardDataService.getWizardData(wiz_ids) 
        .then(function (response) { 
         // How do I access wiz_ids from here? // 
         return response.data; 
        }); 
      }] 
    }, 
} 
+0

您能不能告訴'wizard.step1'狀態配置? – MiTa

回答

2

你可以返回內部then()更復雜的對象。

喜歡的東西:

return WizardDataService.getWizardData(wiz_ids) 
    .then(function(response) { 

    var data = { 
     wiz_ids: wiz_ids, 
     wiz_data: response.data 
    } 

    return data; 
    }); 

然後在控制器訪問各個屬性相應