我得到了以下数据作为回应,我需要达到错误键。任何人都可以指导我如何到达那里并以错误的形式在UI上显示它。
{"error":{"errors":[{"location":"body","param":"email","msg":"Email cannot be empty"},{"location":"body","param":"email","msg":"Email is not valid"}]}}
提前致谢
if (loginModel.username && loginModel.password) {
this.loginService.login(loginModel).subscribe((resp) => {
this.loginService.authStorage.setAuthorizationHeader(resp['success']);
if (resp['success']) {
this.router.navigate(['dashboard']);
}
this.invalidUsernamePassword = true;
console.log(JSON.stringify(resp['error']));
}, (err) => {
console.log(err);
});
我使用了这个角度代码。
答案 0 :(得分:0)
data = { "error": { "errors": [{ "location": "body", "param": "email", "msg": "Email cannot be empty" }, { "location": "body", "param": "email", "msg": "Email is not valid" }] } };
如果回复位于data
属性中,则可以通过
this.data.error.errors.forEach(error => {
console.log(error.msg);
});