Skip to content

Instantly share code, notes, and snippets.

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 {
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