【问题标题】:unable to run uibmodal in typescript无法在打字稿中运行 uibmodal
【发布时间】:2017-04-12 05:21:19
【问题描述】:

我正在尝试使用 $uibModal 使用 typescript 和 angular 来显示模式。

    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']);

我在运行 Gulp Build 时遇到了这个错误:

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

$uibModal 在我运行代码时无法识别: 错误:“PDPController”类型上不存在属性“$uibModal”。

我对 Typescript 完全陌生,无法找到出路。 请指导。

【问题讨论】:

    标签: angularjs typescript angular-ui-bootstrap


    【解决方案1】:

    你没有注入$uibModal。尝试将其添加到您的$inject

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

    【讨论】:

    • 试过了...不行!你能告诉如何解决这个特定的错误->模块'angular.ui'没有导出的成员'bootstrap'。
    【解决方案2】:

    我可以解决这个问题...但真的不知道这是如何工作的! 我所做的编辑:

    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'
            });
        }
    }
    

    如果有人能解释为什么我们需要一个新变量,那就太好了!

    【讨论】:

    • 你错过了 uibModal 并且正在使用 uibModalInstance
    猜你喜欢
    • 2020-09-09
    • 2021-04-14
    • 2020-09-18
    • 2019-03-22
    • 2018-09-23
    • 2016-11-11
    • 2018-08-02
    • 2019-01-21
    • 2023-02-17
    相关资源
    最近更新 更多