【发布时间】:2019-11-08 12:02:59
【问题描述】:
我有一个错误,我不知道为什么,但是 angular 在 spring boot 中没有激活我的 api,我没有找到错误。
这是代码。
服务(角度)
setPost(postId:number):Observable<boolean>{
return this.http.post<boolean>(this.myAppUrl+this.myApiPostUrl+postId+'/setPost',this.authService.getLoggedUserFromSessionStorage())
.pipe(
retry(1),
catchError(this.errorHandler)
);
}
组件(角度)
isAlreadyOpen(){
this.postService.isOpen(this.postId).subscribe( isAuth => {
if(isAuth) {
this.cantModify();
} else {
console.log('im here');
this.postService.setPost(this.postId);
this.router.navigate(['/post/edit/', this.postId]);
}
});
}
代码在else中输入没有问题,因为chrome控制台打印'im here'。
控制器 (JAVA)
@RequestMapping(value = "/posts/{id}/setPost", method = RequestMethod.POST)
public ResponseEntity<Boolean> setPost(@PathVariable("id") int idPost, @RequestBody UserDTO userCorrente) {
PostUser postUser = postUserService.set(idPost, userCorrente);
if (postUser != null) {
return new ResponseEntity<>(true, HttpStatus.OK);
} else {
return new ResponseEntity<>(false, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
角度
this.postService.isOpen(这个api,完美运行)
不工作this.postService.setPost,我试图删除所有地图,看看是否像那样
isAlreadyOpen(){
this.postService.setPost(this.postId);
this.router.navigate(['/post/edit/', this.postId]);
}
}
但是什么都没有,不起作用,我在 Chrome 的 DEV TOOLS(网络)中看不到请求,在 Spring Console 中也看不到任何内容。
【问题讨论】:
标签: java angular spring api spring-boot