Created
October 8, 2017 17:53
-
-
Save NMZivkovic/e047f86ec8dd3607ab527eb220b4dcd2 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 { | |
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