Created
October 8, 2017 19:05
-
-
Save NMZivkovic/89ce43402c2dc28110b642d4fe20a57c to your computer and use it in GitHub Desktop.
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
import { Component, OnInit, ViewEncapsulation } from '@angular/core'; | |
import { User } from '../model/user'; | |
import { UserService} from '../services/users.service'; | |
@Component({ | |
selector: 'users', | |
templateUrl: './users.component.html', | |
}) | |
export class UserComponent implements OnInit { | |
editUser: User; | |
constructor( | |
private userService: UserService | |
) { } | |
ngOnInit() { | |
this.editUser = User.CreateDefault(); | |
} | |
updateUser(user:User) { | |
this.userService | |
.updateUser(this.newUser) | |
.subscribe( | |
data => { | |
var index = this.users.findIndex(item => item._id === this.editUser._id); | |
this.users[index] = this.editUser; | |
this.editUser = User.CreateDefault(); | |
console.log("Added user."); | |
} | |
) | |
} | |
setEditUser(user: User){ | |
this.editUser = new User(user._id, user.name, user.age, user.location, user.blog); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment