Last active
October 25, 2018 17:38
-
-
Save munkacsitomi/9dbb66c0bad6c4c37ef5e19dfae7f71f to your computer and use it in GitHub Desktop.
Angular UserComponent Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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