[英]show modal only after getting form submit response in angular 8
当单击 Angular 8 中的提交按钮时,我正在调用一个弹出窗口,但它在获得响应之前立即显示,因此我需要在获得响应后才显示模式。 有人可以帮我做这件事吗?
这是.html
<div class="modal fade cust_modal save_qut_po" id="sav-popup" tabindex="-1" role="dialog" aria-labelledby="sav-qot-popup" aria-hidden="true">
<input type="submit" class="upload-submit btn btn-primary" value="{{'Save Quotation' | translate}}" data-toggle="modal" data-target="#sav-qot-popup" [disabled]="!Form.form.valid" />
这是我的.ts代码.. 想要在收到605 响应后显示弹出窗口
quotationNo: any;
onSubmit(quotationForm: NgForm, saveQuotation) {
try {
if (quotationForm.form.valid) {
this.submitted = false;
if (this.quotationType)
this.motorQuotation.quotationType = this.quotationType;
this.motorQuotation.addDriver = this.driverList;
this.motorQuotation.premiumDetails = this.premiumDetail;
//var formData = new FormData();
//formData.append('motorQuotation', JSON.stringify(this.motorQuotation));
var formData = this.getFormValue();
this.ruleExecutionResult = this.executeRule();
if (!this.ruleExecutionResult) {
formData.append("actionName", "NEW");
this.quotationCalculation();
}
else {
formData.append("actionName", "APPROVAL");
}
if (formData) {
// this.spinner.show();
this.apiCall.getResponseByPostWithoutToken(this._commonService.quotationFormSubmit, formData).then(
result => {
if (result.data) {
if (result.statusCode == 606) {
this.toastr.error("Error in commiting the data.");
}
if (result.statusCode == 605 && this.ruleExecutionResult) {
this.toastr.info("Quotation " + result.data.responseMessage + " send for underwriter approval.");
this.quotationUnderwriter = true;
this.quotationSuccess = false;
this.isShowPopup = false;
}
if (result.statusCode == 605 && !this.ruleExecutionResult) {
this.toastr.success("Quotation no is: " + result.data.responseMessage);
this.quotationNo = result.data.responseMessage;
this.quotationSuccess = true;
this.quotationUnderwriter = false;
this.sample = true;
this.ref.detectChanges();
this.isShowPopup = false;
// this.loginButton.getNativeElement().click();
}
}
this.spinner.hide();
});
}
}
else {
this.spinner.hide();
this.submitted = true;
}
ng gs service_name
],让我们在那里放一个变量。 可以说它被称为savedResponse
[不要给出类型]。 我们将它用作中间件。 (我建议您使用 Angular http 客户端 - 充分利用 fetch 方法的优势)async
functionasync
function 中写入await
response.json(响应是您的响应)-它将等待响应savedResponse
变量中 [我希望我能看到你的 typescript 代码,这样我就可以告诉更多。 据我了解 - 这与HTML 无关。 HTML仅显示数据,如果您需要较慢的执行- 从typescript执行 - 等待响应(在async
函数中使用await
方法) - 然后显示它]
让我给你举个例子:
这是我的data.service.ts 。 我在这里收到来自 API 的数据
import { Injectable } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { HttpClient } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class DataService {
constructor(private httpCLient: HttpClient) { }
navigateFromDisplayFlag = 0;
currentPurchase;
setPurchase(purchase) {
this.currentPurchase = purchase;
}
getPurchase()
{
return this.currentPurchase;
}
GetPurchases() {
return fetch(('http://localhost:3000/purchases'));
}
}
这是我的组件 class
import { Component, OnInit } from '@angular/core';
import { DataService } from '../data.service';
import { Routes, RouterModule, Router } from '@angular/router';
@Component({
selector: 'app-items-display',
templateUrl: './items-display.component.html',
styleUrls: ['./items-display.component.css']
})
export class ItemsDisplayComponent implements OnInit {
purchases: any;
constructor(private dataService: DataService, private router: Router) {
this.GetPurchases();
}
ngOnInit(): void {
}
async GetPurchases() {
const response = await this.dataService.GetPurchases();
const dataService = await response.json();
this.purchases = dataService;
}
}
你可以看到:
async
方法,在其中我正在等待使用await
的响应
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.