Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Injectable } from '@angular/core';
- import { Http, Headers } from '@angular/http';
- import 'rxjs/add/operator/map';
- @Injectable()
- export class MyClass {
- token_acces: any;
- token_room: any;
- constructor(private http: Http) {
- this.token_acces = null;
- this.token_room = null;
- }
- login(id,pwd){
- let headers = new Headers();
- headers.append('Content-Type', 'application/json');
- this.http.post('/localhost/',
- JSON.stringify({
- username: id ,
- password: pwd
- }), {headers : headers})
- .map(res => res.json())
- .subscribe(data=>{
- this.token_acces = data;
- });
- }
- getToken(){
- return this.token_acces;
- }
- }
- ...
- export class HomePage {
- id: any;
- pwd: any;
- constructor(public navCtrl: NavController, public myClassService: MyClass) { }
- login(): void{
- this.myClassService.login(this.id, this.pwd);
- this.navCtrl.push(SearchPage, { token : this.myClassService.getToken()});
- }
- }
- export class SearchPage {
- token: any;
- constructor(public navCtrl: NavController, public myClassService: MyClass) { }
- ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement