2015-05-06 47 views
0

我在向引導模式注入值時遇到了一些問題。 在模式控制器中,關鍵變量的值未定義。如何向UI注入值。 Bootstrap Modal

代碼以打開模態

var key = 100; 
 
var opts = { 
 
    backdrop: true, 
 
    backdropClick: false, 
 
    dialogFade: false, 
 
    keyboard: true, 
 
    controller: 'modalController', 
 
    controllerAs: 'vm', 
 
    templateUrl: "/app/features/modal/modal.html", 
 
    resolve: { 
 
    key:() => key 
 
    } 
 

 
}; 
 

 
var modalInstance = this.$modal.open(opts);

模態控制器

module Workspace.Controllers { 
 
    "use strict"; 
 
    export interface IModalController { 
 
    ok:() => void; 
 
    cancel:() => void; 
 
    } 
 
    export class ModalController implements IModalController { 
 
    static $inject = ['$modalInstance', 'key']; 
 

 
    constructor(private $modalInstance: any, private key: any) { 
 

 
    } 
 
    public ok =() => { 
 
     this.$modalInstance.close(); 
 
    }; 
 

 
    public cancel =() => { 
 
     this.$modalInstance.dismiss('cancel'); 
 
    }; 
 
    } 
 
}

app.ts

workspaceApp.workspaceModule.controller('modalController', ['$modalInstance', ($modalInstance: any, key: any) => new Controllers.ModalController($modalInstance, key)]);

回答

1

[ '$ modalInstance',($ modalInstance:任意,鍵值:任意)

你缺少'key'這樣的說法會undefined

+0

謝謝Basarat! –