這是我在 Postman 中所做的請求,它作業正常,它只是發送一個顯示值(字串)“true”/“false”來啟用或禁用一個選項卡,然后我簽入獲取請求以獲取所有選項卡并查看它改變了選項卡的值。

事情是在 Angular 中,我正在發送值并且也得到 200OK 回應沒有錯誤但是當我檢查郵遞員獲取請求時,我在前面禁用或啟用的選項卡中沒有任何更改
/**
* get active tabs
*/
public getAvailableTabs() {
return (this.http.get<SiwaTabs[]>(`${ApiProvidersService.CurrentPath()}/Siwa/Settings/SiwaTabs`
).map(tabs => tabs.map(t => new SiwaTabs(
t.id,
t.title,
t.route,
t.UserID,
t.display
))));
}
/**
* set SiwaTabs
* @param display
* @param tabsID
*/
public changeSiwaTabs(display: string, tabsID: number) {
console.log(display, tabsID)
return (this.http.post<any>(`${ApiProvidersService.CurrentPath()}/Siwa/Settings/changeSiwaTabs`, {
display: display,
tabsID: tabsID
}
).map
(result => result));
}
這是訂閱服務的ts檔案
/**
* onInit
* set initial theme
* */
ngOnInit() {
this.getAvailableTabs();
this.openSetting = "none";
this.ReadOnlyStyleGuideNotes = true;
this.Design = this.UserThemes.getTheme(this.User.activeUser.ThemeID);
this.User.setTheme(this.User.activeUser.ThemeID);
this.selectLang(this.User.activeUser.LanguageValue);
this.selectedTabsID(this.Tabs);
this.spinner = new Spinner();
this.timedMessage = new TimedMessage();
let id: number = 2
let display: string = "true"
this.User.changeSiwaTabs(display, id).subscribe((res) => {
console.log(display, id);
console.log(res.status);
if (res.status === true) {
this.timedMessage.show(
"Die Tabs wurden erfolgreich ge?ndert",
"alert-success",
2000
);
}
});
}
這是來自網路瀏覽器的回應:

我做錯了什么?
uj5u.com熱心網友回復:
我認為在changeSiwaTabs功能上,JSON.stringify運營map商是沒用的。
它是一個 POST api,因此有效負載是一個 JSON 物件。您不需要對該有效負載進行字串化。并且map操作員不應該在那里,因為在 中ngOnInit,它已被訂閱。
public changeSiwaTabs(display: string, tabsID: nubmer) {
...
return this.http.post<any>(..., request);
uj5u.com熱心網友回復:
在 get 方法中,你想要布林值,你得到了字串。我對嗎 ?
uj5u.com熱心網友回復:
這是 Access-Control-Allow-Origin 標頭的后端問題
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/486042.html
標籤:有角度的 网页服务 角度服务 角httpclient
下一篇:我有這個錯誤System.ServiceModel.Security.MessageSecurityException
