import { Component , OnInit } from "@angular/core" ; import { ActivatedRoute , Router } from "@angular/router" ; import { User } from "../../core/domains" ; import { UserService } from "../../core/services/user.service" ; import { HttpErrorHandler } from "../../core/services/http-error-handler" ; import { styles } from './user-list.component.styles' ; @ Component ( { selector : 'mpt-user-list' , templateUrl : 'user-list.component.html' , } ) export class UserListComponent implements OnInit { styles : any = styles ; users : User [ ] ; totalPages : number ; page : number ; constructor ( private userService , private errorHandler , private route , private router ) { } ngOnInit ( ) { this . route . params . subscribe ( params => { this . page = + ( params [ 'page' ] || 1 ) ; this . list ( this . page ) ; } ) ; } onPageChanged ( page ) { this . router . navigate ( [ '/users' , { page : page } ] ) ; } private list ( page ) { this . userService . list ( { page : page , size : 5 } ) . subscribe ( usersPage => { this . users = usersPage . content ; this . totalPages = usersPage . totalPages ; } , e => this . errorHandler . handle ( e ) ) ; } }