2017-12-13 8 views
0

解決asyncデータをUiブートストラップモーダルに角度で注入するにはどうすればよいですか? 次のコードは、モーダルを開くコントローラです。解決非同期データをUiブートストラップモーダルに角度で注入するにはどうすればよいですか?

import insertOpportunityModal from './insertOpportunityModal.html'; 

export default class OpportunitiesCtrl { 

    constructor($uibModal, OpportunitiesService, EngagementsService, PAGE_SIZE) { 
    this.$uibModal = $uibModal; 
    this.OpportunitiesService = OpportunitiesService; 
    this.EngagementsService = EngagementsService; 
    } 

    openInsertModal() { 
    var modalInstance = this.$uibModal.open({ 
     animation: false, 
     size: 'md', //['lg', 'md', 'sm'] 
     template: insertOpportunityModal, 
     controller: 'InsertOpportunityModalCtrl', 
     controllerAs: 'vm', 
     resolve: { 
     opportunityTypes: function (EngagementsService) { 
      return EngagementsService.all(); 
     } 
     } 
    }); 

    modalInstance.rendered.then(() => { 
    }); 

    modalInstance.result.then(() => { 
     console.log('modal closed'); 
    }, (error) => { 
     console.log(error); 
    }); 
    } 

} 

OpportunitiesCtrl.$inject = ['$uibModal', 'OpportunitiesService', 'EngagementsService', 'PAGE_SIZE']; 

モーダルコントローラでは、opportunityTypesは未定義です。 同期データでは動作しますが、約束では動作しません。 どのように修正できますか?

export default class InsertOpportunityModalCtrl { 

    constructor($uibModalInstance, OpportunitiesService, opportunityTypes) { 
    this.$uibModalInstance = $uibModalInstance; 
    this.OpportunitiesService = OpportunitiesService; 
    this.opportunityTypes = opportunityTypes; 
    console.log('opportunityTypes', opportunityTypes); 
    } 

    save() { 
    } 

    cancel() { 
    this.$uibModalInstance.dismiss('cancel'); 
    } 

} 

InsertOpportunityModalCtrl.$inject = ['$uibModalInstance', 'OpportunitiesService']; 

答えて

1

は、あなたもInsertOpportunityModalCtrlopportunityTypesを注入する必要があります。

InsertOpportunityModalCtrl.$inject = 
    ['$uibModalInstance', 'OpportunitiesService', 'opportunityTypes']; 
関連する問題