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);
?>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.