@asha4640 wrote:
testing custom api – C:\xampp\htdocs\api\index.php
<?php $mysqli = new mysqli("localhost", "root", "", "test"); $query = "SELECT * FROM content_information"; $dbresult = $mysqli->query($query); while($row = $dbresult->fetch_array(MYSQLI_ASSOC)){ $data[] = array( 'name' => $row['title'] ); } if($dbresult){ $result = "{'success':true, 'data':" . json_encode($data) . "}"; } else { $result = "{'success':false}"; } echo $result; ?>ionic projec t-- C:\xampp\htdocs\test_ionic\sparkTest
home.page.tsimport { Component } from ‘@angular/core’;
import { Router } from ‘@angular/router’;
import { HttpClient } from ‘@angular/common/http’;
import { Observable } from ‘rxjs’;@Component({
selector: ‘app-home’,
templateUrl: ‘home.page.html’,
styleUrls: [‘home.page.scss’],
})
export class HomePage {films: Observable;
constructor(private router: Router, private http: HttpClient) { }
ngOnInit() {
this.films =this.http.get(‘http://localhost/api/index.php’);
this.films.subscribe(data => {
console.log('my data: ', data);
});}
}
home.page.html
<ion-header>
<ion-toolbar>
<ion-buttons slot=“start”>
<ion-menu-button></ion-menu-button>
</ion-buttons>
<ion-title>
Home
</ion-title>
</ion-toolbar>
</ion-header>
<ion-content padding>
{{ films.title }}
</ion-content>
I need to display the title from the database to the ionic home page. but my console showing the below error
Posts: 2
Participants: 1