我是有经验的新手,我在从http客户端获取异步数据时遇到问题,我的代码是
用户服务:
getAll(): Observable<User[]> {
return this.http.get<User[]>(`${this.API_URL}/users`);
}
registerUser(user: User) {
return this.http.post(`${this.API_URL}/api/auth/registerUser`, user);
}
用户模型:
export class User {
id: number;
name: string;
username: string;
surname: string;
email: string;
password: string;
street: string;
numberStreet: string;
postalCode: string;
city: string;
}
用户列表组件:
export class UserListComponent implements OnInit {
public data: User[];
constructor(private userService: UserService, private modalService: NgbModal) {
}
ngOnInit() {
this.getListUsers();
}
getListUsers() {
this.userService.getAll().subscribe(
restItems => {
this.data = restItems;
}
);
}
this.userService.registerUser(this.registerForm.value)
}
现在,如果我添加用户并在数据库中发送帖子,则存储用户,但在前面它不会出现。重新加载页面后工作的用户列表