Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Injectable } from '@angular/core';
- import { Http, Response, Headers } from '@angular/http';
- import { Observable } from 'rxjs/Rx';
- import { User } from './user';
- @Injectable()
- export class UserService {
- public usersTmp: Array<Object> = new Array<Object>();
- public users: Array<User>;
- public user: User = new User();
- public noteToSend;
- constructor(private http: Http) { }
- getUsers() {
- var headers = new Headers();
- headers.append('Accept', 'q=0.8;application/json;q=0.9');
- this.http.get('/AngularApp/api/users', { headers: headers })
- .map((res: Response) => res.json())
- .subscribe(
- data => {
- console.log(data);
- this.usersTmp = data;
- },
- err => console.error(err),
- () => console.log('done')
- );
- this.users = new Array<User>();
- for (var i = 0; i < this.usersTmp.length; i++) {
- this.user = new User();
- this.user.id = this.usersTmp[i]["userId"];
- this.user.name = this.usersTmp[i]["userName"];
- this.user.email = this.usersTmp[i]["userEmail"];
- this.user.pass = this.usersTmp[i]["userPassword"];
- this.users.push(this.user);
- }
- return this.users;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement