Skip to content

Instantly share code, notes, and snippets.

@NMZivkovic
Created October 8, 2017 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NMZivkovic/89ce43402c2dc28110b642d4fe20a57c to your computer and use it in GitHub Desktop.
Save NMZivkovic/89ce43402c2dc28110b642d4fe20a57c to your computer and use it in GitHub Desktop.
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