我正在为我的web应用程序使用Angular-7。在项目中,我应用了sweetalert2。
client.component.ts
import { Component, OnInit, ElementRef, NgZone, ViewChild } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { ApiService } from '../../shared/services/api.service';
import { TokenService } from '../../shared/services/token.service';
import { Router } from '@angular/router';
import { SnotifyService } from 'ng-snotify';
import swal from 'sweetalert2';
import { FormControl } from "@angular/forms";
import { MapsAPILoader } from '@agm/core';
onSubmit(){
this.notify.clear();
var header = {
'Content-Type': 'application/json'
}
return this.api.post('clientquotelanding', this.form, header).subscribe(
response => {
swal.fire(
'Congratulations!',
'Your Quote have been successfully received. You will hear from us shortly through the provided email. Thank you!',
'success'
)
},
error => this.errorHandle(error),
this.router.navigateByUrl('/landing')
);
}我遇到的问题是,当我点击submit按钮时,页面会在sweetalert2消息弹出之前重定向到登录页面。我该如何解决这个问题?
发布于 2019-09-20 11:19:40
问题出在this.router.navigateByUrl('/landing')语句上。你应该把它放在成功的内部。订阅接受oncomplete操作的第三个参数。
试试这样的东西。
response => {
swal.fire(
'Congratulations!',
'Your Quote have been successfully received. You will hear from us shortly through the provided email. Thank you!',
'success'
);
this.router.navigateByUrl('/landing')
},你可以阅读更多关于它的here。
发布于 2019-09-20 12:47:53
swal({
title: 'Are you sure?',
text: "You won't be able to revert this!",
type: 'warning',
showCancelButton: true,
confirmButtonClass: 'btn btn-success',
cancelButtonClass: 'btn btn-danger',
confirmButtonText: 'Yes, delete it!',
buttonsStyling: false
}).then((result) => {
if (result.value) {
this.router.navigateByUrl('/landing');
}
})https://stackoverflow.com/questions/58021308
复制相似问题