我在向引导模式注入值时遇到一些问题。
在模态控制器中,关键变量的值未定义。
代码打开模态
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');
};
}
}
应用程序
workspaceApp.workspaceModule.controller('modalController', ['$modalInstance', ($modalInstance: any, key: any) => new Controllers.ModalController($modalInstance, key)]);
最佳答案
['$ modalInstance',($ modalInstance:any,key:any)
您缺少'key'
,因此参数将为undefined
。