Passing string on another page


#1

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 passt the user session id, i want to click on the name of a user on the home page and pass its id 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

import { 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();
}

I did this and i am getting the session user id on the console. Any help? Thanks
}


#2

If you got rid of all the anys and replaced them with interfaces, maybe somebody could have a better idea of what is supposed to go where, but as it is, I can’t see how anybody could.


#3

anys? You mean the responseData and dataSet?


#4

Those and userDetails. If you are unhappy with what is coming into UserPage's uid parameter, you either have to change what you are passing into it or change what is stored in this.userPostData.uid and keep the push() call as it is. I don’t know which choice makes more sense for your situation.


#5

The userDetails holds the parameters for const data = JSON.parse(localStorage.getItem(“userData”)); right? I use the parmeters after the user logs in and return them. In the home page i display users that are friends with the user in session. I got the part that the uid that passes to the UserProfile page is the session id and i know why is that. I don’t know how to pass the id of a friend as returned in friendsNewsFeed the PHP script that i call to return the friends of the user in session.