Advertisement
Guest User

Untitled

a guest
Feb 10th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. import { Injectable } from '@angular/core';
  2. import { Http, Headers } from '@angular/http';
  3. import 'rxjs/add/operator/map';
  4.  
  5. @Injectable()
  6. export class MyClass {
  7. token_acces: any;
  8. token_room: any;
  9.  
  10. constructor(private http: Http) {
  11. this.token_acces = null;
  12. this.token_room = null;
  13. }
  14.  
  15. login(id,pwd){
  16. let headers = new Headers();
  17. headers.append('Content-Type', 'application/json');
  18. this.http.post('/localhost/',
  19. JSON.stringify({
  20. username: id ,
  21. password: pwd
  22. }), {headers : headers})
  23. .map(res => res.json())
  24. .subscribe(data=>{
  25. this.token_acces = data;
  26. });
  27. }
  28.  
  29. getToken(){
  30. return this.token_acces;
  31. }
  32.  
  33. }
  34.  
  35. ...
  36. export class HomePage {
  37. id: any;
  38. pwd: any;
  39.  
  40. constructor(public navCtrl: NavController, public myClassService: MyClass) { }
  41.  
  42. login(): void{
  43. this.myClassService.login(this.id, this.pwd);
  44. this.navCtrl.push(SearchPage, { token : this.myClassService.getToken()});
  45. }
  46. }
  47.  
  48. export class SearchPage {
  49. token: any;
  50.  
  51. constructor(public navCtrl: NavController, public myClassService: MyClass) { }
  52. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement