【发布时间】:2021-09-02 01:17:57
【问题描述】:
我在 Angular 7 上工作,我遇到了无法从 Angular 7 调用 Web API 返回布尔值的问题
那么如何在 Angular 7 上调用 Web API 返回真或假
[HttpGet]
[Route("CompareExcel/SelectedOptions")]
public IActionResult CompareExcel( int SelectedOptions)
{
var DisplayFileName = Request.Form.Files[0];
string fileName = DisplayFileName.FileName.Replace(".xlsx", "-") + Guid.NewGuid().ToString() + ".xlsx";
string Month = DateTime.Now.Month.ToString();
string DirectoryCreate = Path.Combine(myValue1, Month);// myValue1 + "\\" + Month + "\\" + fileName;
CExcel ex = new CExcel();
string error = "";
int rowCount = 0;
var selectedFile = "";
var filedata = ContentDispositionHeaderValue.Parse(Request.Form.Files[0].ContentDisposition).FileName.Trim('"');
var dbPath = Path.Combine(DirectoryCreate, fileName);
if (SelectedOptions == 1)
{
selectedFile = "Gen.xlsx";
}
else if(SelectedOptions == 2)
{
selectedFile = "DeliveryGeneration_Input.xlsx";
}
var InputfilePath = System.IO.Path.Combine(GetFilesDownload, selectedFile);
using (var stream = new FileStream(dbPath, FileMode.Create))
{
Request.Form.Files[0].CopyTo(stream);
stream.Flush();
stream.Close();
}
GC.Collect();
bool areIdentical = ex.CompareExcel(dbPath, InputfilePath, out rowCount, out error);
if(areIdentical==true)
{
return Ok(true);
}
else
{
return Ok(false);
}
}
用于从 Angular 调用 Web API 的链接
http://localhost:61265/api/DeliverySys/CompareExcel/SelectedOptions?=1
当调用它上面的函数时,它只返回布尔值 true 或 false
如果比较excel相同则返回true
如果比较excel不一样则返回false
so on angular service.ts
//what I write
component Type script ts
what I write
html component
what I write
更新帖子
on service ts i do as below :
CompareExcel(SelectedOptions)
{
this.http.get('http://localhost:61265/api/DeliverySys/CompareExcel/SelectedOptions?=' + SelectedOptions).subscribe(result => {
console.log(result);
});
}
on component ts
i call it as
this._dataService.CompareExcel(this.selectedoptions.toString())
so are this correct
on component html
what i write
【问题讨论】:
标签: angular angular-material asp.net-core-webapi angular7 angular-components