Skip to content

Instantly share code, notes, and snippets.

@munkacsitomi
Last active October 25, 2018 17:38
Show Gist options
  • Select an option

  • Save munkacsitomi/9dbb66c0bad6c4c37ef5e19dfae7f71f to your computer and use it in GitHub Desktop.

Select an option

Save munkacsitomi/9dbb66c0bad6c4c37ef5e19dfae7f71f to your computer and use it in GitHub Desktop.
Angular UserComponent Example
export class UserComponent implements OnInit {
users: User[];
constructor(private userService: UserService) {}
ngOnInit() {
this.userService.getUsers().subscribe((users: User[]) => this.users = users);
}
userCreated(user: User) {
this.users = [...this.users, user];
}
userUpdated(user: User) {
this.users = this.users.map(u => u.id === user.id ? u = user : u);
}
userDeleted(user: User) {
this.users = this.users.filter(u => u.id !== user.id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment