以可观察的角度9更新数据

时间:2020-04-06 13:13:04

标签: angular observable fetch behaviorsubject

在添加用户时,Html表无法刷新,我如何用可观察的方法使它出现问题,我在 register中有 AccountService 方法< / strong>和 getAllAdmins UsersService 中,并且在管理员List组件中,在 getAllAdmins上订阅后获取数据/ em>方法

UsersService

export class UsersService {

  constructor(private http: HttpClient) { }

  HTTP_URL = environment.HTTP_URL;

  getAllAdmins(): Observable<any> {
    return this.http.get(this.HTTP_URL + 'UserProfile/GetAdmins'));
  }

AccountService

export class AccountService {

  constructor(private http: HttpClient) { }

  HTTP_URL = environment.HTTP_URL;

  register(reg: RegisterModel): Observable<RegisterModel> {
    return this.http.post<RegisterModel>(this.HTTP_URL + 'ApplicationUser/Register' , reg).pipe();
  }

此功能来自AdminsListComponent.ts

getAdmins() {
    this.usersService.getAllAdmins().subscribe(list => {
      this.admins = list;
    });
  }

0 个答案:

没有答案