【发布时间】:2020-04-19 12:33:09
【问题描述】:
当我将一个值插入 SQL 数据库时,我正在使用 Angular 和 Typescript 进行验证,它会检查该值是否已经在数据库表中。我从 ASP .NET CORE API 得到响应,如果值已经在表中,数据库服务器将返回 true。
回复是这样的:
true
例如,我已经在数据库表中有值“1”,然后我尝试插入值“1”,但它会将其插入表中,当我再次尝试插入该值时,它将停止并且不会让我插入它。如果我刷新页面,即使数据库表中有 >10 个“1”值,也会发生相同的过程。我可以使用什么来解决此问题以及如何解决?
FileCount:boolean;
getFileCount() {
this.http.get<boolean>(this.BaseURL + '/Count/File?Name=' + this.formData.Name)
.subscribe(
result => {
this.FileCount = result;
console.log(this.FileCount);
}
);
}
insertRecord(form: NgForm) {
this.getFileCount();
if (this.FileCount == true) {
this.toastr.warning('Submitted failed', 'There is another file with the name: "' + this.formData.Name + '"');
}
else {
this.postFile().subscribe(
res => {
this.toastr.success('Submitted successfully', 'File Creation Complete');
this.refreshList();
},
(err) => {
console.log(err);
}
);
}
}
postFile() {
return this.http.post(this.BaseURL + '/File', this.formData);
}
【问题讨论】:
标签: angular typescript asynchronous promise async-await