我想向用户显示一条 toast 消息,其中包含我在变量中的名字。是否可以?如果是这样,怎么办?
我想做这样的事情:
this.toastCtrl.create({
message: "Welcome user.firstname" ,
duration: 3000
}).present();
其中 user.firstname
包含我用户的名字。
PS:上面的代码不起作用,它显示消息“Welcome user.firstname”
最佳答案
您可以向 toast 添加参数
async toastCtrl(msg) {
const toast = await this.toastController.create({
message: msg,
duration: 300
});
toast.present();
}
使用变量调用函数
this.toastCtrl('Welcome ' + user.firstname);
关于angularjs - 是否可以在 Ionic 或 Angular 中将变量与 toastController 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54628549/