2016-11-28 32 views
0

我正在嘗試使用打字稿和角度顯示使用$ uibModal的模式。無法在打字稿中運行uibmodal

export class PDPController{ 

    static $inject = ['pdpService', '$sce', 'angularLoad', '$uibModalInstance']; 
    constructor(
     pdpService: PDPService, 
     $sce : ng.ISCEService, 
     angularLoad, 
     //initiating in constructor 
     private $uibModalInstance:ng.ui.bootstrap.IModalServiceInstance 
    ) { 
     this.pdpService=pdpService; 
     //Need to add promise 
     pdpService.getContentdata(APP_CONSTANT.API_URL_LEARN_MORE) 
      .then((authorContentData) => { 
      this.contentData= authorContentData; 
      pdpService.getPDPdata(APP_CONSTANT.API_URL_LEARN_MORE) 
      .then((pdpData) => { 
      console.log(pdpData); 
      this.setProductDetails(pdpData); 
     }); 
     }); 

    } 
    //method to invoke the modal 
    private showPromo(): void{ 

     console.log("Promo"); 
      var modalInstance = this.$uibModal.open({ 
       animation: "true", 
       templateUrl: 'promoModalContent.html', 
       appendTo: 'body' 
      }); 
    } 
} 

//module: 
let module: ng.IModule = angular.module(pdpModule, ['ui.bootstrap']); 

當我運行咕嘟咕嘟構建我面對這個錯誤:

Unknown provider: $uibModalInstanceProvider <- $uibModalInstance 
Module 'angular.ui' has no exported member 'bootstrap'. 

$ uibModal不被識別,當我運行代碼: 錯誤:屬性「$ uibModal」不上類型存在'PDPController'。

我是全新的Typescript,無法想出這裏的出路。 請指導。

回答

0

您沒有注入$uibModal。嘗試將其添加到您的$inject

static $inject = ['pdpService', '$sce', 'angularLoad', '$uibModalInstance', '$uibModal']; 
+0

試過...不工作! 可以請你告訴如何解決這個特定的錯誤 - > 模塊'angular.ui'沒有導出成員'bootstrap'。 – Aashish

0

我能解決這個問題......但真的不知道這是如何工作! 編輯我提出:

export class PDPController { 
    public $uibModal: ng.ui.bootstrap.IModalService; 
    public modal: any; 

    //injected $uibModal 
    static $inject = ['pdpService', '$sce', 'angularLoad', '$uibModal']; 
    //initiated $uibModal 
    constructor(
     pdpService: PDPService, 
     $sce: ng.ISCEService, 
     angularLoad, 
     $uibModal: ng.ui.bootstrap.IModalService 
    ) { 
     // i had to assign the value of $uibModal to a new variable, otherwise 
     //$uibModal is undefined when accessed in the function showPromo(). 
     this.modal = $uibModal; 
    } 

    private showPromo(): void { 

     let modalInstance = this.modal.open({ 
      animation: "true", 
      templateUrl: 'promoModalContent.html' 
     }); 
    } 
} 

這將是巨大的,如果有人可以解釋爲什麼我們需要一個新的變量!