Angular+ionic实现退出功能
2020-07-22 13:42
806 查看
Angular+ionic实现退出功能
1,html中
<div class="delivery-address-content-footer" (click)="logoutConfirm()"> <span>退出当前账户</span> </div>
2,ts中
引入AlertController import { ToastController, LoadingController, NavController,AlertController } from '@ionic/angular'; export class SetUpPage extends UserInfo implements OnInit { constructor( private rest: RestService, private router: Router, private activatedRoute: ActivatedRoute, public appService: AppService, private loadingCtrl: LoadingController, private toastCtrl: ToastController, private navCtrl: NavController, public localStorageService: StorageService, private storageService: StorageService, private alertController: AlertController, //引入AlertController ) { super(appService, localStorageService); } } async logoutConfirm() { const alert = await this.alertController.create({ header: '提醒', message: '确定退出登录吗?', buttons: [ { text: '取消', role: 'cancel', cssClass: 'secondary', handler: (blah) => { } }, { text: '确定', handler: () => { this.logout();//执行退出方法 } } ] }); await alert.present(); } //调用接口:logout async logout() { this.showLoading(this.loadingCtrl, '退出中...').then((loading) => { this.rest.apiPost('', this.rest.logout + '/' + localStorage.getItem('QZH_TOKEN')) .subscribe((res) => { if (res.status === 200) { this.toastSuccess(this.toastCtrl, '退出成功'); this.storageService.removeToken(); //清除密码及账号 // this.storageService.removeStorage('username'); // this.storageService.removeStorage('password'); // this.storageService.removeStorage('userId'); // this.appService.userInfoEvent.emit('update');] this.goBack(); } else { this.toastError(this.toastCtrl, res.msg); } loading.dismiss(); }, (err) => { this.toastError(this.toastCtrl, err.msg); loading.dismiss(); }); }); }
3,踩坑,关键代码
不可以传参,这里会报错,有坑。
使用传空,拼接localStorage.getItem就可以实现退出功能
this.rest.apiPost('', this.rest.logout + '/' + localStorage.getItem('QZH_TOKEN'))
相关文章推荐
- Ionic 实现双击返回键退出功能
- ionic监听android返回键实现“再按一次退出”功能
- Ionic 实现双击返回键退出功能 基于ngcordova
- Ionic Angular 实现验证码倒计时功能
- Ionic+AngularJS实现登录和注册带验证功能
- Ionic + Angular.js实现验证码倒计时功能的方法
- Ionic 实现双击返回键退出功能
- ionic实现双击返回键退出功能
- ionic 实现双击返回键退出应用功能
- Ionic 实现双击返回键退出功能
- ionic实现双击返回键退出功能
- [转]Ionic 实现双击返回键退出功能
- [转]Ionic 实现双击返回键退出功能
- IONIC 中使用拦截功能来实现API接口访问的数据缓存
- HTML+AngularJS+Groovy如何实现登录功能
- angular+ionic 的app上拉加载更新数据实现
- Angular实现模版驱动表单的自定义校验功能(密码确认为例)
- ionic+AngularJs项目中实现三级联动效果,筛选省份、城市、区县
- Angular+ionic实现折叠展开效果
- Ionic系列——android双击退出应用和物理返回按钮隐藏键盘的实现