简体   繁体   中英

Unable to get the parameter from URL in angular js and pass it to PHP

I have a product page where products from database is showing. Code for that product page.

<!-- language: lang-html -->

<div class="tab-content vertical col-md-10 col-lg-10 col-sm-9 col-xs-9 left-aligned">
<div class="tab-pane fade in active">
<perfect-scrollbar wheel-propagation="true" suppress-scroll-x="true"  min-scrollbar-length="8" class='ps-scrollbar'>
<div class="ecommerce_product col-lg-3 col-md-4 col-sm-4 col-xs-6" ng-repeat="products in data | filter:search | startSearchFrom:(currentPage-1)*entryLimit | limitTo:entryLimit">
<div class="thumb">
<img class="img-responsive" ng-src="../upload/{{products.image}}">
<div class="overlay"><a ng-href="#/app/ecommerce/product-edit?id={{products.id}}" data-ng-click="editUser(products)" ><i class="material-icons">shopping_cart</i></a></div>
</div>
<div class="product-info">
<h4><a ui-sref="app.mus-song-view"><b>{{ products.pname | limitTo: 8 }}{{products.pname > 8 ? '...' : ''}}</b></a></h4>
<p class="price"> <b>Price:</b> {{products.price}}</p>
<p class="price"><b>Sale Price:</b>{{products.price - products.discount | number:2}}</p>
</div>
</div>
</perfect-scrollbar>
</div>
</div>

<!-- end snippet -->

Now the problem is i want to edit a particular product in a different page when clicked on the product. I passed the id in the url. But i am not being able to call the url parameter from the controller and at the same time pass the parameter to a php file so that i can call the data from the database.

Is there anyone who can help me from this. Please.

To get a url param you can use: $routeParams

For example you can get the id of a product from that route:

www.yoursite.com/product/id

by doing:

var id = $routeParams.id

In you HTML/PHP page after you pass param to the URL Suppose your URL will be example.com/edit?id=1 and in the page when you visit above URL.

<?php 
$id = $_GET['id'];
?>
<div ng-controller="my_ctrl">
   <input type="hidden" ng-model="myID" value="<?php echo $id; ?>" />
   {{myID}}
</div>

Now in your angular controller my_ctrl you can access your value (id) by using myID In your controller (my_ctrl):

//.............
$scope.myID = ""; //Initial Value
//.............

Remember Angular is both way data binding framework, so if you change the value of a model in you HTML will reflect on JS and if you change value in JS will reflect on View.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM