Javascript 单击“发布链接”在另一页上显示完整结果

Javascript 单击“发布链接”在另一页上显示完整结果,javascript,php,html,angularjs,Javascript,Php,Html,Angularjs,我想单击数据库中id为的链接(在posts.html页面上),然后使用AngularJS、MySQLi和PHP在display.html中查看该帖子链接的完整内容。请参见下图: 以下是我迄今为止所做的工作: Posts.html <table class="table table-bordered" ng-controller="postController" ng-init="show_data()"> <tr> <th&g

我想单击数据库中id为的链接(在posts.html页面上),然后使用AngularJS、MySQLi和PHP在display.html中查看该帖子链接的完整内容。请参见下图:

以下是我迄今为止所做的工作: Posts.html

<table class="table table-bordered" ng-controller="postController"
       ng-init="show_data()">
    <tr>
        <th>Description</th>
    </tr>
    <tr ng-repeat="x in news">
        <td><a href="">{{x.description}}</a></td>
    </tr>
</table>
下面是我的display.php代码:

<?php
    require_once "config.php";
    $output = array();
    $query  = "SELECT * FROM news";
    $result = mysqli_query($conn, $query);
    if (mysqli_num_rows($result) > 0) {
    while ($row = mysqli_fetch_array($result)) {
    $output[] = $row;
    }
    echo json_encode($output);
    }
    ?>

My display.html是:

<div >
    <div>{{id}}</div>
    <div>{{title}}</div>
    <div>{{article}}</div>
    <div>{{tag}}</div>
    <div>{{author}}</div>
</div>

{{id}
{{title}}
{{条款}
{{tag}}
{{作者}

如何在display.html上显示从特定链接的数据库中获取的结果?

这应该可以完成以下工作:

在您的配置中:

app
  .config(function ($routeProvider ...) {
    $routeProvider
      ...
      .when('/posts', {templateUrl: 'posts.html', controller: function($scope, $http) {
        $scope.getPosts = function() {
          $http.get('posts.php').then(function (response) {
            $scope.posts = response.data;
          });
        };
      }})

      .when('/display/:id', {templateUrl: 'display.html', controller: function($scope, $routeParams, $http) {
        $http.get('display.php', {id: $routeParams.id}).then(function (response) {
          $scope.post = response.data;
        });
      }})
    })
posts.html
中:

<table class="table table-bordered" ng-controller="postController" ng-init="getPosts()">
  <tr>
    <th>Description</th>
  </tr>
  <tr ng-repeat="post in posts">
    <td><a ng-href="display/{{post.id}}">{{post.description}}</a></td>
  </tr>
</table>
<div ng-if="post">
  ...
  <div>{{post.title}}</div>
  ...
</div>
display.php
中:

$id = $_GET['id'];
// then retrieve post by this id and return as json item

Angular和mysqli从未见过面。如果是mysqli,那么就是mysqli和PHP。当它是有角度的-那么它是有角度的和PHP。从angularjs的角度来看,PHP从何处获得json并不重要。
.success
方法已经被删除。我正在使用angularjs 1.5.8,.success和.error方法已经从angularjs 1.6中删除。无论如何,谢谢你的信息@georgeawg
$id = $_GET['id'];
// then retrieve post by this id and return as json item