angular - 调用服务后如何调用不同的 Ionic toast?
问题描述
出于某种原因,在角度控制器中的服务响应之后,我遇到了调用离子吐司的问题。
基于响应的精确字符串,我必须初始化不同的消息。我已经检查了服务的正确响应(按我的预期工作)。
这是我所做的:
showToast(position: string, message: string) {
let toast = this.toastCtrl.create({
message: message,
duration: 2000,
position: position
});
toast.present(toast);
}
logForm() {
console.log(this.userRegister.value);
this.utente = this.userRegister.value;
this.UtentiService.addUser(this.utente);
//controllo se l'utente esiste già
this.UtentiService.getSingleUser(this.utente).subscribe(
data => {
this.risposta = JSON.stringify(data.messaggio);
},
error => {
console.log(error);
},
() => {
alert(this.risposta);
if (this.risposta === "ko_singoloFound") {
this.showToast('bottom', 'Ti sei registrato con successo!');
}
if (this.risposta === "ok_singoloFound") {
this.showToast('middle', 'Utente già registrato!');
}
});
}
显然,该函数似乎不会出现在最后一个回调中的 if 语句中。
我做错了什么?谢谢你
解决方案
显然问题出在 JSON.stringify(data.messaggio); 答案已经是一个字符串并返回给我 ""ko_singoloFound"" ko_singoloFound。
推荐阅读
- sql-server - 如何将 varchar 转换为十进制,以便在 Excel 中将其视为数字
- json - 在java中展平一个json结构
- php - 如何使 jquery 呈现活泼的 PDF 视图 laravel 刀片
- aws-lambda - 设备影子更新时触发 Lambda
- git - 将所有权转移到其他帐户后未找到私有存储库
- python - 如何在 python 中提高支持向量机的准确性?
- angular - 根据设备重定向 - Angular
- javascript - Yii2隐藏表单域onchange radio
- python - 在 PyTorch 中显示增强图像的示例
- javascript - 用嵌套对象展平数组