简体   繁体   English

无法从angular js中的URL获取参数并将其传递给PHP

[英]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. 我在网址中传递了ID。 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. 但是我无法从控制器调用url参数,同时将参数传递给php文件,以便我可以从数据库中调用数据。

Is there anyone who can help me from this. 有没有人可以帮助我。 Please. 请。

To get a url param you can use: $routeParams 要获取url参数,可以使用:$ routeParams

For example you can get the id of a product from that route: 例如,您可以从该路线获取产品的ID:

www.yoursite.com/product/id 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. 在将参数传递给URL之后,在HTML / PHP页面中,假设您的URL为example.com/edit?id=1并且在您访问上述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): 现在,在您的角度控制器my_ctrl您可以通过访问您的值(ID) myID在你的控制器(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. 请记住,Angular是双向数据绑定框架,因此,如果您更改模型中的值,则HTML会反映在JS上,如果您更改JS中的值,则会反映在View上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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