2017-10-26 1 views
1

API를 사용하여 내 loginpage에서 데이터를 검색했습니다. 이제 해당 데이터에 액세스하려고합니다. tabspage는 로그인 성공 후 열리는 페이지이므로 탭 페이지의 데이터에 액세스 할 수 있습니다. 홈페이지, 프로필 페이지 등 다른 페이지에서 해당 데이터에 액세스 할 수 없습니다.내 탭 페이지의 데이터에는 액세스 할 수 있지만 내 응용 프로그램의 내 홈페이지에는 액세스 할 수 없습니다.

tabspage 또는 loginpage에서 내 데이터에 액세스 할 수있는 몇 가지 코드 또는 개념을 알려주십시오. loginPage

var headers = new Headers(); 
    //headers.append('Content-Type', 'application/x-www-form-urlencoded'); 
    headers.append('Content-Type', 'application/x-www-form-urlencoded'); 
    let options = new RequestOptions({headers: headers}); 
    let postParams ='&password='+ this.loginpass + '&phone=' + this.loginmob; 
    // console.log(JSON.stringify(postParams)); 
    this.http.post("http://www.btedge.appexperts.net/Ionic_Webservices/login.php", JSON.stringify(postParams), options) 
    .map(
     (res:Response) => { return console.log(this.users=res.json());}) 
     .subscribe(data => { 
     if(this.users.success=="1") 
      { 

       this.loadingCtrl.create({ 
       content: 'Login Successfully... ', 
       duration: 4000, 
       dismissOnPageChange: true 
       }).present(); 
      //alert(this.users.user_id); 
      this.navCtrl.push(TabsPage,{user_id: this.users.user_id,distributor_id: this.users.distributor_id,user_name:this.users.user_name,user_email:this.users.user_email,user_phoneno:this.users.user_phoneno,user_address:this.users.user_address,distributor_name:this.users.distributor_name,distributor_phoneno:this.users.distributor_phoneno,distributor_address:this.users.distributor_address,distributor_email:this.users.distributor_email}); 


      } 
     else if(this.users.success=="2") 
      { 
      alert("Phone no or Password Incorrect"); 
      //this.navCtrl.push(HomePage); 
      } 
     else if(this.users.success=="0") 
      { 
      alert("Required Fields Blank.."); 
      //this.navCtrl.push(HomePage); 
      }  
     }, 
    error=>{console.log(error)}); 

TabsPage- 여기에

은 내가 더 전화를 액세스 할 수 없습니다 나는이 페이지에 아무 로그인 페이지

import { Component } from '@angular/core'; 
import { AppModule } from '../../app/app.module'; 
import { AlertController,LoadingController } from 'ionic-angular'; 
import { NavController, NavParams } from 'ionic-angular'; 
import { AboutPage } from '../about/about'; 
import { ProfilePage } from '../profile/profile'; 
import { LoginPage } from '../Login/Login'; 
import { HomePage } from '../home/home'; 
import { MsgPage } from "../message/message"; 

@Component({ 
    selector: 'page-tabs', 
    templateUrl: 'tabs.html' 
}) 
export class TabsPage { 
users: any; 
    tab1Root = HomePage; 
    tab2Root = MsgPage; 
    tab3Root = AboutPage; 
    tab4Root = ProfilePage; 
    userphone: any; 


    constructor(public navCtrl: NavController,private navParams : NavParams) { 

    this.userphone=this.navParams.get('user_phoneno'); 
    console.log(this.userphone); 
    } 

} 

HomePage-에서 오는 전화에 액세스 할 수있게되었습니다. 내가 여기서 뭘해야하지?

import { Component } from '@angular/core'; 
import { AppModule } from '../../app/app.module'; 
import { AlertController,LoadingController } from 'ionic-angular'; 
import { NavController, NavParams } from 'ionic-angular'; 

import { AboutPage } from '../about/about'; 
import { ProfilePage } from '../profile/profile'; 
import { LoginPage } from '../Login/Login'; 
import { TabsPage } from "../tabs/tabs"; 

@Component({ 
    selector: 'page-home', 
    templateUrl: 'home.html', 

}) 
export class HomePage { 
    userphone: String; 
    useremail: String; 
    constructor(public navCtrl: NavController, private navParams : NavParams) { 
    this.userphone=this.navParams.get('user_phoneno'); 
    console.log(this.userphone); 


    } 

} 
+0

답변을 제외하고, 앱에서 데이터를 사용할 수있게하려면 이벤트를 조사하고 싶을 수도 있습니다. https://ionicframework.com/docs/api/util/Events/ – Alex

답변

0

사용 [rootParams]="userData" TabsPage에서 HTML 레이아웃.

Set userData = {user_phoneno : this.navParams.get ('user_phoneno')};

마지막으로 navparams는 TabsPage의 모든 페이지를 가져올 수 있습니다.

+0

도움을 많이 주셔서 감사합니다. 그것은 효과가 :) –

+0

그리고 만약 내가 tabpage의 다른 페이지에 여러 매개 변수를 갖고 싶어? 하나의 변수 데이터에 대해 솔루션이 작동했습니다. 나는 더 많은 변수 즉, phoneno, 이메일, 이름, id 등을 가지고있다. 내가 어떻게 얻을 수 있는지 말해 줄 수 있니? –

+0

당신은 매개 변수를 객체로 설정할 수있다 => var 객체 = {user_phoneno : this.navParams.get (' user_phoneno '), data : "value"};' 그리고 this.navParams.data를 얻을 수 있습니다. 또는'this.navParams.get (""). propertyName' –

0

로그인 :

var headers = new Headers(); 
    //headers.append('Content-Type', 'application/x-www-form-urlencoded'); 
    headers.append('Content-Type', 'application/x-www-form-urlencoded'); 
    let options = new RequestOptions({headers: headers}); 
    let postParams ='&password='+ this.loginpass + '&phone=' + this.loginmob; 
    // console.log(JSON.stringify(postParams)); 
    this.http.post("http://www.btedge.appexperts.net/Ionic_Webservices/login.php", JSON.stringify(postParams), options) 
    .map(
     (res:Response) => { return console.log(this.users=res.json());}) 
     .subscribe(data => { 
     if(this.users.success=="1") 
      { 

       this.loadingCtrl.create({ 
       content: 'Login Successfully... ', 
       duration: 4000, 
       dismissOnPageChange: true 
       }).present(); 
      //alert(this.users.user_id); 
    localStorage.setItem('userdata', this.users); 
      this.navCtrl.setRoot(TabsPage); 


      } 
     else if(this.users.success=="2") 
      { 
      alert("Phone no or Password Incorrect"); 
      //this.navCtrl.push(HomePage); 
      } 
     else if(this.users.success=="0") 
      { 
      alert("Required Fields Blank.."); 
      //this.navCtrl.push(HomePage); 
      }  
     }, 
    error=>{console.log(error)}); 

홈 페이지 : (모든 <ion-tab> 태그)

import { Component } from '@angular/core'; 
import { AppModule } from '../../app/app.module'; 
import { AlertController,LoadingController } from 'ionic-angular'; 
import { NavController, NavParams } from 'ionic-angular'; 

import { AboutPage } from '../about/about'; 
import { ProfilePage } from '../profile/profile'; 
import { LoginPage } from '../Login/Login'; 
import { TabsPage } from "../tabs/tabs"; 

@Component({ 
    selector: 'page-home', 
    templateUrl: 'home.html', 

}) 
export class HomePage { 
    userphone: String; 
    useremail: String; 
    userData:any; 
    constructor() { 

    this.userData = localStorage.getItem('userdata'); 
    this.userphone=this.userData.user_phoneno; 
    console.log(this.userphone); 


    } 

} 
+0

데이터에 액세스 할 수는 있지만. 그러나 홈 페이지는이 코드를 사용하여 열리게됩니다. 하지만 tabspage에 가고 싶습니다. 그 후 다른 페이지로 이동하면 데이터에 액세스 할 수 있어야합니다. –

+0

@BellTesting : 데이터를 전송할 때 내 대답을 업데이트하고 localstorage를 사용했습니다. –

+0

작동하지 않습니다. 같은 일이 일어나고 있습니다 tabspage에 데이터를 액세스 할 수 있지만 홈페이지에 액세스 할 수 없습니다 –

관련 문제