Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 是否可以将变量与toastController一起以离子或角度使用?_Angularjs_Ionic Framework_Ionic3_Toast - Fatal编程技术网

Angularjs 是否可以将变量与toastController一起以离子或角度使用?

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

我想用我在变量中的名字向用户呈现一条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);
简单地做:

this.toastCtrl.create(
    { 
        message: "Welcome " + user.firstname, 
        duration: 3000 
    }
).present();

为什么不简单地说“欢迎”+user.firstname呢?你已经知道答案了。toast中显示的
消息是一个字符串。只要连接你的字符串,你就完成了!将其包装到函数中比简单地执行
“Welcome”+user.firstname
,如何提高性能?因为如果需要,您可以使用toastController处理不同的消息。我真正的困难是如何连接