Hello i can’t return data from MySql. The data are returned ok on Console->Netowrk-> XHR but i can’t return them on .ts file. I use an auth-service file to connect to database
home.ts
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 photos: any;
public base64Image: string;
public fileImage: string;
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.getFeed();
}
ngOnInit() {
this.dataSet = [];
}
getFeed() {
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");
}
);
}
converTime(time) {
let a = new Date(time * 1000);
return a;
}
backToWelcome() {
const root = this.app.getRootNav();
root.popToRoot();
}
logout() {
//Api Token Logout
localStorage.clear();
setTimeout(() => this.backToWelcome(), 1000);
}
}
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);
});
});
}
}
home.html
<ion-card *ngFor=“let item of dataSet; let id = index”>
<p [innerHTML]=“item.message | linky”>