簡體   English   中英

在 memory angular 中找不到發布錯誤 404

[英]Post error 404 not found using in memory angular

這里

m trying to create a ,但是當我嘗試發布它時,它給出了一個 POST ERROR 404 (NOT FOUND)。 如何解決這個問題試圖復制英雄之旅但得到了這個錯誤,我認為我得到了正確的但奇怪的是我得到了錯誤 404(未找到)。

在 MEMORY 服務

@Injectable({
  providedIn: 'root'
})
export class InMemoryDataService implements InMemoryDbService {

  createDb() {
    const serials = [
  
  {id: 1, deliveryReceiptDetailsId: 0, itemCode:'testing', qtyReceived:0 },
  {id: 2, deliveryReceiptDetailsId: 0, itemCode:'sample1', qtyReceived:0  },
  {id: 3, deliveryReceiptDetailsId: 0, itemCode:'sample2', qtyReceived:0  },
  {id: 4, deliveryReceiptDetailsId: 0, itemCode:'sample3', qtyReceived:0 },
  {id: 5, deliveryReceiptDetailsId: 0, itemCode:'sample4', qtyReceived:0 },
  {id: 6, deliveryReceiptDetailsId: 0, itemCode:'sample5', qtyReceived:0 },
];
console.log(serials)
return {serials};
}

服務

const httpOptions = {
  headers: new HttpHeaders({
    'Content-Type' : 'application/json',
    'Authorization' : 'my-auth-token'
  })
}

@Injectable({
  providedIn: 'root'
})
export class SerialCodeService {
  url = 'api/serials';


  constructor(private http: HttpClient) { }

  getHeroes(): Observable<SerialCodeDTO[]> {
    return this.http.get<SerialCodeDTO[]>(this.url)
      .pipe(
        catchError(this.handleError)
      );
  }
  /** POST: add a new hero to the database */
  addHero(serial: SerialCodeDTO): Observable<SerialCodeDTO> {
    return this.http.post<SerialCodeDTO>(this.url, serial, httpOptions)
      .pipe(
        catchError(this.handleError)
      );
  }

在將其導入 AppModule 時,您必須確保在HttpClientInMemoryWebApiModuleAppModule方法中注冊InMemoryDataService

imports: [
  ...,
  HttpClientInMemoryWebApiModule.forRoot(InMemoryDataService),
  ...
]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM