使用最新的 Angular
Angular CLI: 6.0.0
Node: 8.11.1
OS: win32 x64
Angular: 6.0.0
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, http, language-service, material, platform-browser
... platform-browser-dynamic, router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.6.0
@angular-devkit/build-angular 0.6.0
@angular-devkit/build-optimizer 0.6.0
@angular-devkit/core 0.6.0
@angular-devkit/schematics 0.6.0
@ngtools/webpack 6.0.0
@schematics/angular 0.6.0
@schematics/update 0.6.0
rxjs 6.1.0
typescript 2.7.2
webpack 4.6.0
我正在研究角度并探索不同的http
请求,例如,GET
和现在的.POST
PUT
PATCH
但是当我使用该PATCH
方法时遇到问题,我只是复制该PUT
方法并将其更改PUT
为PATCH
,因为我认为它们只是具有相同的参数和功能。但我遇到一个错误:
service.ts
const heroesUrl = "api/heroes";
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
};
patchHero(hero: Hero): Observable<any> {
return this.http.patch(heroesUrl, hero, httpOptions)
.pipe(
tap(_ => this.log(`patched hero id=${hero.id}`)),
catchError(this.handleError<any>('patchHero'))
);
}
component.ts
update(id: number, name: string): void {
this.heroService.patchHero({id, name } as Hero)
.subscribe(() => {
console.log("Success update") // This log is printing even if the Method not allow is appeared.
});
}
我只是在工作和练习它网站上给定教程的角度。