Angularjs 是否可以将变量与toastController一起以离子或角度使用?
我想用我在变量中的名字向用户呈现一条toast消息。可能吗?如果是,怎么做 我想这样做:Angularjs 是否可以将变量与toastController一起以离子或角度使用?,angularjs,ionic-framework,ionic3,toast,Angularjs,Ionic Framework,Ionic3,Toast,我想用我在变量中的名字向用户呈现一条toast消息。可能吗?如果是,怎么做 我想这样做: this.toastCtrl.create({ message: "Welcome user.firstname" , duration: 3000 }).present(); 其中user.firstname包含我的用户名 PS:上面的代码不起作用,它显示消息“Welcome user.firstname”您可以向toast添加参数 async toastCtrl(msg) { const
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);
简单地做:
this.toastCtrl.create(
{
message: "Welcome " + user.firstname,
duration: 3000
}
).present();
为什么不简单地说“欢迎”+user.firstname呢?你已经知道答案了。toast中显示的
消息是一个字符串。只要连接你的字符串,你就完成了!将其包装到函数中比简单地执行“Welcome”+user.firstname
,如何提高性能?因为如果需要,您可以使用toastController处理不同的消息。我真正的困难是如何连接