Understanding how to pass a PHP variable in ng-click is one thing, but passing a complete PHP object through the ng-click function seems to be a challenge. I have successfully passed a JavaScript object through it, but when it comes to passing a PHP object, I am stuck. Any help on this matter would be greatly appreciated. Below is the script I am working with:
<ul>
<!-- Retrieving main products -->
<?
if(isset($products)):
foreach($products as $row):
?>
<li>
<a href="products/<?=$row->sub_c_id?>/<?=$row->pid?>" class="title colr"><?=$row->pname?></a>
<a href="products/<?=$row->sub_c_id?>/<?=$row->pid?>" class="thumb">
<img src="<?php echo base_url(); ?>uploads/<?=$row->product_pic?>" style="width:157px; height:181px;" alt="" />
</a>
<div class="prodbuttons">
<p class="price bold"><?=$row->pprice?></p>
<a class="cart upper" ng-click="addtocart(<?=$row->pid?>,'<?=$this->session->userdata('session_id'); ?>','<?=$row->pname?>',<?=$row->pprice?>,<?=$row->pquantity?>,<?=$row->sub_c_id?>,'<?=$row->product_pic?>','<?=$row->color?>','<?=$row->size?>',1)">Add to Cart</a>
<a ng-click="check(<? json_encode($row) ?>)">email me</a>
</div>
</li>
<? endforeach; endif; ?>
</ul>
I also tried the following approach, but encountered an error:
<a ng-click="check(<? echo json_encode($row) ?>)">email me</a>
This is the AngularJS script being used:
$scope.addtocart=function(pid,current_session_id,pname,pprice,pquantity,sub_c_id,product_pic,color,size,qty){
$scope.errors.splice(0, $scope.errors.length); // remove all error messages
$scope.msgs.splice(0, $scope.msgs.length);
$http.post('/product/ng_insertincart', { pid : pid, current_session_id : current_session_id, pname : pname, pprice : pprice, pquantity : pquantity,sub_c_id : sub_c_id,product_pic : product_pic,color : color,size : size, qty : qty}
).success(function(data, status, headers, config) {
if (data.msg != '')
{
$scope.msgs.push(data.msg);
console.log(data);
}
else
{
$scope.msgs.push(data.msg);
}
}).error(function(data, status) {
$scope.errors.push(status);
});
}
$scope.check=function(argument) {
console.log(argument);
}