Skip to content

Instantly share code, notes, and snippets.

@NMZivkovic
Created Oct 8, 2017
Embed
What would you like to do?
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