0
내가 각도 JS에 새로운 오전,각도 JS 동적 HTML 내가 PHP에서 동적으로 만든 HTML에 NG 클릭 이벤트를 만들고 싶어
작동하지 NG가 클릭 여기에 코드입니다.
var app = angular.module('pageapp',[]);
angular.module('pageapp')
.filter('to_trusted', ['$sce', function($sce){
return function(text) {
return $sce.trustAsHtml(text);
};
}]);
app.controller('productList',function($scope,$http){
$http.get("../webservice/api/get-products")
.success(function(response){
$scope.products = response.data;
$scope.paginationLinks = response.links;
});
$scope.getPageData = function() {
alert("Hello");
}
});
HTML ...
<section ng-controller="productList">
<table class="table table-responsive table-hover">
<thead>
<tr>
<th>S.No</th>
<th>Name</th>
<th>Color</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="product in products">
<td>{{$index + 1}}</td>
<td>{{product.name}}</td>
<td>{{product.color}}</td>
<td>{{product.price}}</td>
</tr>
</tbody>
</table>
<ul class="pagination pull-right" ng-bind-html="paginationLinks|to_trusted""></ul>
</section>
PHP .. 대신 PHP에서 ng-click='getPageData(".$i.")
을 추가
public function Products(){
$start = 0;
$perPage = 10;
$count = DB::table('products')->count();
$totalPages = ceil($count/$perPage);
$data = DB::table('products')
->select('name','price','color')
->take($perPage)
->skip($start)
->get();
for ($i=1; $i <= $totalPages; $i++) {
if($i == 1)
$links ="<li><a href=''>".$i."</a></li>";
else
$links .="<li><a href='' ng-click='getPageData(".$i.")'>".$i."</a></li>";
}
return [
'totalpages' =>$totalPages,
'data' =>$data,
'links' =>$links
];
}