[英]I am getting ERROR TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator)) error
I am using angular 8 at front end and java spring boot at back end while running the application I am getting this error. 我在运行应用程序时在前端使用angular 8,在后端使用java spring boot,但出现此错误。 I am new to angular and I guess the error is because of response body from back end but I couldn't solve it. 我刚接触角度,我猜该错误是由于后端的响应主体引起的,但我无法解决。
I have tried the other answers but nothing seems to work. 我尝试了其他答案,但似乎无济于事。
auth.service.ts 验证服务
// Method from server should return QueryResultsModel(items: any[], totalsCount: number)
// items => filtered/sorted result
findUsers(queryParams: QueryParamsModel): Observable<QueryResultsModel> {
const httpHeaders = new HttpHeaders();
httpHeaders.set('Content-Type', 'application/json');
return this.http.post<QueryResultsModel>(API_USERS_URL + '/use' + '/findUsers', queryParams, { headers: httpHeaders});
}
Web service java spring boot Web Service Java春季启动
// Get All User
@PostMapping(value = "/user/use/findUsers")
public ResponseEntity<List<User>> getAllUserFind() {
try {
return new ResponseEntity<>((List<User>)userService.getAllUser(), HttpStatus.OK);
} catch (Exception e) {
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
You need to find out the exact cause of error by gracefully catching the error in your observable resolution. 您需要通过以可观察的分辨率正常捕获错误来找出错误的确切原因。 Use 采用
return this.http.post<QueryResultsModel>(API_USERS_URL + '/use' + '/findUsers', queryParams, { headers: httpHeaders})
.pipe(catchError(error)=>{
console.log(error);
return of(null);
});
This will print out the exact error on your console. 这将在您的控制台上打印出确切的错误。 Remember to import Rx Operators. 记住要导入Rx运算符。
import { of } from 'rxjs';
import { catchError } from 'rxjs/operators';
Metronic theme ? 美敦力主题?
It's an amazing Template. 这是一个了不起的模板。
QueryResultsModel is a Model QueryResultsModel是一个模型
// fields
items: any[]; <---- This is where you should iterate
importedCount?: number;
activeCount?: number;
totalCount: number;
errorMessage: string;
Good Luck ! 祝好运 !
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.