如何使用angularJS和php在单独的页面中显示特定表的更多细节

时间:2016-07-11 06:59:25

标签: javascript php html angularjs ionic-framework

This is My database

This is my html page

我使用了ng-repeat并且能够在数据库中显示数据。 我想在单独的弹出页面中单击“了解更多”按钮时显示特定表格的更多信息。 我怎么能在angularjs中实现这个目标?

.controller('far_req_disp', function($scope, $http) {
  $http.get('php/far_req_disp.php')
    .success(function(data) {
      $scope.request = data;
    })
    .error(function() {
      $scope.error = "error";
    });
})
<div ng-controller="seller_post_disp">
  <ion-list ng-repeat="a in usr007">
    <h2>{{a.crop_id}}</h2>
    <p>Villiage:{{a.village}} & District :{{a.DIST}}</p>
    <p>Expected Price:{{a.expec_price}} {{a.Per}}</p>

    <p>Date of availability:From {{a.from_date}} To {{a.to_date}}</p>
    <a class="button" ng-click="knowMore()">Know More </a>
  </ion-list>
</div>

1 个答案:

答案 0 :(得分:1)

只需将您的数据对象传递给您的知识函数,如下所示:

<a class="button" ng-click="knowMore(a)">Know More </a>

1)并在您的函数中捕获该数据,如:

$scope.knowmore = function(data){
    console.log(data); // 
};

2)否则,如果您在单独的页面中使用详细信息,请广播您的对象并像这样捕捉它。

$scope.knowmore = function(data){
    $scope.$broadcast('seller_post, data);
};

使用$ scope。$ broadcast将触发$ scope范围内的事件。使用$ scope。$ on是我们监听这些事件的方式。现在,您可以通过赶上“loadPost”事件在控制器中使用它。

// listen for the event in the relevant $scope
$scope.$on('seller_post', function (event, data) {
   console.log(data); 
});