Hello i have a problem with my Ionic App. I am using typescript files. I am getting console log No Access
that means there is a problem with resposeData
. Any hint? I am really stuck
home.ts file
import { Component, ViewChild } from "@angular/core";
import { NavController, App, AlertController } from "ionic-angular";
import { AuthService } from "../../providers/auth-service";
import { Common } from "../../providers/common";
import { Camera, CameraOptions } from "@ionic-native/camera";
@Component({ selector: "page-home", templateUrl: "home.html" })
export class HomePage {
@ViewChild("updatebox") updatebox;
public userDetails: any;
public resposeData: any;
public dataSet: any;
public noRecords: boolean;
userPostData = {
uid: "",
token: "",
created: "",
message: ""
};
constructor(
public common: Common,
private alertCtrl: AlertController,
private camera: Camera,
public navCtrl: NavController,
public app: App,
public authService: AuthService
) {
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.created = "";
this.noRecords = false
this.userNewsFeed();
}
userNewsFeed() {
this.common.presentLoading();
this.authService.postData(this.userPostData, "userNewsFeed").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
console.log("Nac");
}
);
}
}
home.html
<ion-card *ngFor="let item of dataSet; let id = index"> <ion-item> <ion-card-content> <p [innerHTML]="item.uid | linky"></p> </ion-card-content> </ion-item> </ion-card>
php script userNewsFeed
function userNewsFeed(){
$request = \Slim\Slim::getInstance()->request();
$data = json_decode($request->getBody());
$uid=$data->uid;
$token=$data->token;
$created = $data->created;
$systemToken=apiToken($uid);
try {
$friendsNewsFeed = '';
$db = getDB();
if($created){
$sql = "SELECT * FROM messages WHERE uid_fk=:uid AND created < :created ORDER BY msg_id DESC LIMIT 5";
$stmt = $db->prepare($sql);
$stmt->bindParam("uid", $uid, PDO::PARAM_INT);
$stmt->bindParam("created", $created, PDO::PARAM_STR);
}
else{
$sql = "SELECT * FROM messages WHERE uid_fk=:uid ORDER BY msg_id DESC LIMIT 5";
$stmt = $db->prepare($sql);
$stmt->bindParam("uid", $uid, PDO::PARAM_INT);
}
$stmt->execute();
$friendsNewsFeed = $stmt->fetchAll(PDO::FETCH_OBJ);
$db = null;
if($friendsNewsFeed)
echo '{"friendsNewsFeed ": ' . json_encode($friendsNewsFeed) . '}';
else
echo '{"friendsNewsFeed ": ""}';
} catch(PDOException $e) {
echo '{"error":{"text":'. $e->getMessage() .'}}';
}
}