消息如下所示: 具体如下:" {"时间戳":1500492972729,"状态":500,"错误":"内部服务器错误",& #34; exception":" java.lang.RuntimeException"," message":"用户名已经存在","路径": " /注册"}"
this.userService.create(this.model)
.map((response: Response) =>{
const data = response.json();
const extractedChars = data.results;
const chars = extractedChars.map((char) =>{
return { message: char.message}
});
return chars;
})
.subscribe(
(data) => {
console.log(data);
this.alertService.success('Registration successful', true);
this.router.navigate(['/login']);
},
(error) => {
this.alertService.error(error);
this.loading = false;
}
);
答案 0 :(得分:0)
我通过使用json()然后使用.message来引用消息来解决这个问题。 json()将它转换为对象。
(error) => {
const results = error.json();
this.alertService.error(results.message);
this.loading = false;
}