我使用了 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>
最佳答案
只需将您的数据对象传递给您的 Knowmore 函数,如下所示:
<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”事件来跨 Controller 使用它。
// listen for the event in the relevant $scope
$scope.$on('seller_post', function (event, data) {
console.log(data);
});
关于javascript - 如何使用 angularJS 和 php 在单独的页面中显示特定表的更多详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38300869/