$http.get file php, but I want to show more data

16 views
Skip to first unread message

alessandro schirinzi

unread,
Jan 26, 2016, 4:08:20 AM1/26/16
to AngularJS
Please can you help me? I fetch some news in php with ajax in a page news.html,  but I want to click every news and show more details about the clicked news, for example (body of the news) in a page newsdetail.html. I'm not using json, only php file hosted in my server. I'm using a template app downloaded from github. What I have missed? 

This is the code:

Thanks to all


-- news.html --

<ion-view title="news">
   
<ion-content class="has-header">

<div ng-repeat="x in names">
 
Id: {{x.Id }}
<br>
Author: {{ x.Author }}
<br>
Title: {{ x.Title }}
<br>

<hr>

</div>

   
</ion-content>
</ion-view>

-- controllers.js --

angular.module('taufan.ionizer.app.controllers', [])

//news controller
.controller('myctrl', function($scope, $http, IonizerService) {
$http
.get("http://localhost//show_news_app.php")
   
.then(function (response) {$scope.names = response.data.records;});

})


app.js (here I've already set route for newsDetail.html with controllers)

angular.module('taufan.ionizer.app', ['ionic', 'taufan.ionizer.app.controllers', 'taufan.ionizer.app.services', 'taufan.ionizer.app.directives', 'taufan.ionizer.app.filters'])

.state('app.news', {
    url
: "/news",
    views
: {
     
'menuContent': {
        templateUrl
: "templates/news.html",
        controller
: "myctrl"
     
}
   
}
 
})
 
 
.state('app.newsdetail', {
    url
: "/news/:newsId",
    views
: {
     
'menuContent': {
        templateUrl
: "templates/newsDetail.html",
        controller
: 'NewsDetailCtrl'
     
}
   
}
 
})


-- php file --

<?php
header
("Access-Control-Allow-Origin: *");
header
("Content-Type: application/json; charset=UTF-8");


$conn
= new mysqli("localhost", "root", "password", "test");


$result
= $conn->query("SELECT Id, Author, Title, Text FROM post");


$outp
= "";
while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
   
if ($outp != "") {$outp .= ",";}
 $outp
.= '{"Id":"'  .$rs["Id"] . '",';
    $outp
.= '"Author":"'  . $rs["Author"] . '",';
    $outp
.= '"Title":"'   . $rs["Title"]        . '",';
    $outp
.= '"Text":"'. $rs["Text"]     . '"}';
}
$outp
='{"records":['.$outp.']}';
$conn
->close();


echo
($outp);
?>

Reply all
Reply to author
Forward
0 new messages