Updating user.component.ts

Within the ngOnInit method, make use of the user service to get all users from the API:

ngOnInit() {this.userService.getUser().subscribe(users => {console.log(users);this.users = users;});}

Below the ngOnInit method, write a method that makes use of the post method in the user service to add new users:

addUser(event) {event.preventDefault();var newUser = {name: this.name,email: this.email,phone_number: this.phone_number,isOnline: false};this.userService.addUser(newUser).subscribe(user => {this.users.push(user);this.name = '';this.email = '';this.phone_number = '';});}

Let's make use of the delete method from the user service to enable us to delete users:

deleteUser(id) {var users = this.users;this.userService.deleteUser(id).subscribe(data ...

Get TypeScript 2.x for Angular Developers now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.