31.10. User Resolver - get user by id (#31)

This commit is contained in:
Art
2021-10-09 09:17:16 +03:00
parent 517ac7b44d
commit b9ef56302b
4 changed files with 34 additions and 2 deletions

View File

@ -0,0 +1,19 @@
import {Injectable} from '@angular/core';
import {ActivatedRouteSnapshot, Resolve, RouterStateSnapshot} from "@angular/router";
import {User} from "../../../model/user";
import {Observable} from "rxjs";
import {UserService} from "../../../service/user.service";
@Injectable({
providedIn: 'root'
})
export class UserResolver implements Resolve<User> {
constructor(private userService: UserService) {
}
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<User> | Promise<User> | User {
const id = route.params['id'];
return this.userService.findUserById(id);
}
}

View File

@ -18,7 +18,7 @@ export class UserViewComponent implements OnInit {
}
ngOnInit(): void {
this.user = this.userService.getSelectedUser();
this.route.data.subscribe((data) => this.user = data['user']);
setTimeout(() => this.clickButton('openUserInfo'), 100);
}