Skip to content

Instantly share code, notes, and snippets.

@NMZivkovic
Created October 8, 2017 17:53
Show Gist options
  • Save NMZivkovic/e047f86ec8dd3607ab527eb220b4dcd2 to your computer and use it in GitHub Desktop.
Save NMZivkovic/e047f86ec8dd3607ab527eb220b4dcd2 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 {
users: User[];
searchCriteria: string;
constructor(
private userService: UserService
) { }
ngOnInit() {
this.searchCriteria = '';
this.getUsers();
}
getUsers(){
this.userService.getUsers(this.searchCriteria)
.subscribe(
data => {
this.users = [];
data.forEach(
element => {
var newUser = new User(element._id,
element.name,
element.age,
element.location,
element.blog);
this.users.push(newUser);
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment