0

Hello i want to pass the user id (uid) from the home page to a user Details Page. Because i display multiple users on my home page i don’t wan to pass the user session id (as given by the JSON.parse(localStorage.getItem("userData")); ), i want to click on the name of any user on the home page and pass its id and other parameters on the user details page.

home.html
<p (click)="UserPage()" [innerHTML]="item.username | linky"></p>

home.ts

public userDetails: any;
public resposeData: any;
public dataSet: any;
public noRecords: boolean;
rootPage: any = HomePage;
pages: Array<{ title: string, component: any }>;
userPostData = {
uid: “”,
token: “”,
username: “”,
message: “”,
msg_id: “”,
title: “”,
description: “”,
media_pic: “”,
created:""
};

constructor(
    public common: Common,
    public navCtrl: NavController,
    public app: App,
    public menu: MenuController,
    public authService: AuthService,
    platform: Platform,
    statusBar: StatusBar,
    splashScreen: SplashScreen,
) {
    const data = JSON.parse(localStorage.getItem("userData"));
    this.userDetails = data.userData;
    this.userPostData.uid = this.userDetails.uid;
    this.userPostData.token = this.userDetails.token;
    this.userPostData.username = this.userDetails.username;
    this.userPostData.msg_id = this.userDetails.msg_id;
    this.userPostData.message = this.userDetails.message;
    this.userPostData.title = this.userDetails.title;
    this.userPostData.description = this.userDetails.description;
    this.userPostData.media_pic = this.userDetails.media_pic;
    this.userPostData.created = this.userDetails.created;
    this.noRecords = false
    this.allArtists();

}

note: this is how i call the users via Auth Service

allArtists() {
this.common.presentLoading();
this.authService.postData(this.userPostData, “newsFeed”).then(

        result => {
            this.resposeData = result;
            if (this.resposeData.friendsNewsFeed) {
                this.common.closeLoading();
                this.dataSet = this.resposeData.friendsNewsFeed;
                console.log(this.dataSet);

            } else {
                console.log("No access");
            }
        },
        err => {
            //Connection failed message
        }
    );
}

UserPage() {
this.navCtrl.push(UserPage, { uid: this.userPostData.uid });

userProfile.ts

mport { NavController, App, AlertController, MenuController, NavParams } from “ionic-angular”;

export class UserPage {
public uid: string;

constructor(
public common: Common,
public navCtrl: NavController,
public app: App,
public menuCtrl: MenuController,
public navParams: NavParams,
public authService: AuthService
) {
this.uid = navParams.get(‘uid’);

        console.log(this.uid);
    this.userProfile();
}

}

auth-service.ts

import { Injectable } from '@angular/core';
import { Http, Headers } from '@angular/http';
import 'rxjs/add/operator/map';

let apiUrl = "http://localhost/PHP-Slim-Restful1/api/";
//let apiUrl = 'https://api.thewallscript.com/restful/';
/*
  Generated class for the AuthService provider.

  See https://angular.io/docs/ts/latest/guide/dependency-injection.html
  for more info on providers and Angular 2 DI.
*/
@Injectable()
export class AuthService {

  constructor(public http: Http) {
    console.log('Hello AuthService Provider');
  }

  postData(credentials, type){

    return new Promise((resolve, reject) =>{
      let headers = new Headers();
      this.http.post(apiUrl+type, JSON.stringify(credentials), {headers: headers}).
      subscribe(res =>{
        resolve(res.json());
      }, (err) =>{
        reject(err);
      });

    });

  }

}
1
Contributor
0
Replies
7
Views
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.