Angular-提交后模态表格不重定向

时间:2019-10-23 13:02:38

标签: angular

我正在使用Angular-7开发客户端门户。该应用程序具有模式形式。

transaction.component.ts

  ngOnInit() {

    this.notify.clear();
    this.notify.info("Loading...", {timeout: 0});
    if(this.keyword) {
      // tslint:disable-next-line:max-line-length
      this.api.get('transaction?search=' + this.keyword + '&page=' + this.pagination.page + '&sort=' + this.sortData.col + '&order=' + this.sortData.order, this.headers).subscribe(
        data => this.datahandler(data),
        error => { this.notify.clear(); this.notify.error(error.error.message) }
      );
    } else {
      // tslint:disable-next-line:max-line-length
      this.api.get('transaction?page=' + this.pagination.page + '&sort=' + this.sortData.col + '&order=' + this.sortData.order, this.headers).subscribe(
        data => this.datahandler(data),
        error => { this.notify.error(error.error.message) }
      );
    }
  }


  add(){
    this.notify.clear();
    this.form.phone = null;
    this.form.address = null;
    this.form.truck_required = null;
    this.form.truck_type = null;
    this.form.quote_origin = null;
    this.form.quote_destination = null;
    this.form.commodity = null;
    this.form.loading_date = null;
    this.form.comment = null;
    this.form.quote_status = null;
    var modal = document.getElementById('addModal');
    modal.style.display = "block";
  }

  addModalSubmit(){
    this.notify.clear();
    this.notify.info("Wait...", {timeout: 0});
    this.api.post('clientquote', this.form, this.headers).subscribe(
      data => {
        this.notify.clear();
        this.notify.info("Quote Added Successfully", {timeout: 2000});
        this.router.navigateByUrl('/transaction-success');
        this.closeAddModal();
      },
      error => { this.notify.clear(); this.error = error.error.errors; }
    );

  }

  closeAddModal(){
    this.error = {
      'first_name' : null,
      'last_name' : null,
      'email' : null,
      'phone' : null,
      'address' : null,
      'business_name' : null,
      'truck_required' : null,
      'truck_type' : null,
      'quote_origin' : null,
      'quote_destination' : null,
      'commodity' : null,
      'loading_date' : null,
      'comment' : null,
      'responded' : null,
      'quote_status' : null
    };
    var modal = document.getElementById('addModal');
    modal.style.display = "none";
  }

当我单击索引页面上的“添加”按钮时,它将加载模式表单以添加事务。

但是,当我单击模式表单上的Submit时,它应该重定向到 transaction-success 页面并关闭模式表单。取而代之的是,它关闭模式形式,保留在索引页面上,并且没有重定向到交易成功页面。

该如何解决?

0 个答案:

没有答案