自定义对话中的持有的CustomDialogController变量为undefined
咨询场景描述:当对话框new CustomDialogController 出现在局部方法中
代码:在组件中增加方法如下,则TMsgDialog中持有的CustomDialogController为undefined
showMsgDialog(msg: string) {
let dialogController = new CustomDialogController({
builder: TMsgDialog({
msg: msg,
rightBtn: "我知道了",
rightCallback: () => {
dialogController.close();
}
}),
customStyle: true,
autoCancel: false,
alignment: DialogAlignment.Center,
maskColor: 0x77000000
});
dialogController.open();
}
这是因为这里在方法中写的controller是一个局部变量,dialogController的声明应该是在@Component中作为一个变量进行初始化,此外,也不能动态的对dialogController进行赋值。