首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在单击确定之前,Angular - Sweetalrt2重定向

在单击确定之前,Angular - Sweetalrt2重定向
EN

Stack Overflow用户
提问于 2019-09-20 11:12:12
回答 2查看 152关注 0票数 0

我正在为我的web应用程序使用Angular-7。在项目中,我应用了sweetalert2。

client.component.ts

代码语言:javascript
复制
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消息弹出之前重定向到登录页面。我该如何解决这个问题?

EN

回答 2

Stack Overflow用户

发布于 2019-09-20 11:19:40

问题出在this.router.navigateByUrl('/landing')语句上。你应该把它放在成功的内部。订阅接受oncomplete操作的第三个参数。

试试这样的东西。

代码语言:javascript
复制
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

票数 0
EN

Stack Overflow用户

发布于 2019-09-20 12:47:53

代码语言:javascript
复制
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');
        }
      })
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58021308

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档