我目前正在嘗試使用 angular 的服務器創建一個創建函式(參考)。所以我在html檔案中做了一個輸入表單。
<form [formGroup]="addquoteform" (submit)="createquote()">
<p>
<mat-form-field appearance="outline">
<mat-label>quote</mat-label>
<input matInput placeholder="Placeholder" formControlName="quote">
<mat-icon matSuffix>sentiment_very_satisfied</mat-icon>
</mat-form-field>
</p>
<p>
<button mat-raised-button color="primary">Submit</button>
</p>
</form>
然后我在 .ts 檔案中創建了這個函式。
createquote(){
this.dbService.addquote(this.addquoteform.value)
.subscribe(data => {
console.log("new quote")
}, err => {
console.log(err);
})
}
然后我在 server/quote.ts 中參考
interface QuoteData {
quote : string;
}
export interface quote extends QuoteData{
}
然后在 services/dbService.ts 檔案中我做了 this.http.post()
addquote(quoteObj: any) {
return this.http.post(this.baseUrl 'quote', quoteObj);
}
但是最后一個不行。我得到的只是錯誤:
POST http://localhost:4200/quote 404 (Not Found)
我嘗試更改鏈接,但似乎沒有任何幫助。知道是什么原因造成的嗎?
uj5u.com熱心網友回復:
原因可能是第一個:后端的端點不匹配。第二:后端可能對配置中的所有API都有API前綴,你再檢查一下。那是http://localhost:4200/api/qoute
uj5u.com熱心網友回復:
您是否嘗試呼叫任何后端 api?因為它不會嘗試使用埠 4200 在您的前端應用程式上呼叫 thay api。這顯然不存在。它只能為資產資料呼叫前端。如果要呼叫后端,請確保后端也在運行或服務器正在運行。因為查看上面的資訊,它無法路由到您的服務器。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/348015.html
