Advertisement
Guest User

edit.component.ts

a guest
Dec 7th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component, OnInit } from '@angular/core';
  2. import { ActivatedRoute, Params }   from '@angular/router';
  3.  
  4. import { User } from '../shared/index';
  5. import {UserService} from '../../../_services/index';
  6.  
  7.  
  8. import { Response } from '@angular/http';
  9. import { Observable } from 'rxjs';
  10.  
  11. @Component({
  12.     moduleId: module.id,
  13.     templateUrl: 'edit.component.html',
  14.     providers: [UserService]
  15. })
  16.  
  17. export class UserEditComponent implements OnInit {
  18.  
  19.     public user:User[];
  20.  
  21.     constructor(
  22.         private route:ActivatedRoute,
  23.         private http:UserService) {
  24.  
  25.     }
  26.  
  27.     ngOnInit() {
  28.  
  29.         this.route.params.subscribe(params => {
  30.             this.search(+params['id']);
  31.             //return this.http.getUser(+params['id'])
  32.             //    .subscribe((data)=> { this.user = data; });
  33.         });
  34.     }
  35.  
  36.  
  37.     search(id: number): Observable<User[]> {
  38.         return this.http
  39.             .getUser(id)
  40.             .map((r: Response) => r.json().data as User[]);
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement