【发布时间】:2020-01-05 23:08:44
【问题描述】:
在这里,我正在使用 Angular 4 Web 应用程序上的 post 方法。输入数据并单击确认按钮时,值(数据)被保存到数据库中。它工作成功,但我的问题是同时post 方法完成后,ID(返回值)正在从 DB 传递到 API(对于 Angular )以获取另一个函数参数。在这里如何将该值带到我的角度?我希望该值作为下一个函数参数。实际上,如果我的问题有任何问题,请原谅我。 (我想要从 api 到 angular 的 TransactionId 值)
这是我的打字稿(TS 文件)
onClick() {
this.header = new IHeaderstock(this.userid, this.created, this.CompanyID,
this.modified, this.modifieduserid, this.confirm, this.shopid);
this.headeritems.push(this.header);
this._enqService.CatchHeaderDetail(this.headeritems)
.subscribe(value => {
if (typeof value !== 'undefined' && value != null) {
value.forEach(header => {
this.headeritems.push(this.header)
});
}
},
error => {
console.error(error);
this.statusMessage = "Problem with the service.Please try again after sometime";
});
additem{
this.items = new IStockitems(this.shopid,value.ItemCode, value.ItemDescription, value.PackingtypeName, value.Stock, this.TransactionId );
} //here this.TransactionId is the returned value from the above post method.
这是我的服务文件
CatchHeaderDetail(stock: any)
: Observable<IHeaderstock[]> {
let stockheaderdetail = stock;
console.log(stockheaderdetail)
debugger;
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this._http.post('http://localhost:3071/api/Stockcountheader/' + 'Stock', stockheaderdetail, options)
.map((response: Response) => <IHeaderstock[]>response.json())
.catch(this.handleError);
}
这是我的 WebAPI(注意我的 API 成功返回值)
My API is(it is working fine)
public class StockcountheaderController : ApiController
{
private adminv2Entities enqentities = new adminv2Entities();
[HttpPost]
private IActionResult Stock([FromBody] List<spGetNewStockCountHeader_Result>
jsonvalues)
{
ObjectParameter TransactionId = new ObjectParameter("TransactionId", typeof(Int32));
foreach (spGetNewStockCountHeader_Result Datastock in jsonvalues)
{
spGetNewStockCountHeader_Result Stockobject = new spGetNewStockCountHeader_Result();
Stockobject.UserID = Datastock.UserID;
Stockobject.created = Datastock.created;
Stockobject.CompanyID = Datastock.CompanyID;
Stockobject.modified = Datastock.modified;
Stockobject.modifieduserid = Datastock.modifieduserid;
Stockobject.confirm = Datastock.confirm;
Stockobject.ShopId = Datastock.ShopId;
enqentities.spGetNewStockCountHeader(Datastock.UserID, Datastock.created, Datastock.CompanyID, Datastock.modified, Datastock.modifieduserid, Datastock.confirm,Datastock.ShopId, TransactionId);
}
return Ok(new { data = TransactionId.Value});
}
【问题讨论】:
标签: angular typescript angular-services angular4-forms angular4-httpclient