繁体   English   中英

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

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

我有一个产品页面,其中显示了来自数据库的产品。 该产品页面的代码。

<!-- 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 -->

现在的问题是,单击产品后,我想在其他页面中编辑特定产品。 我在网址中传递了ID。 但是我无法从控制器调用url参数,同时将参数传递给php文件,以便我可以从数据库中调用数据。

有没有人可以帮助我。 请。

要获取url参数,可以使用:$ routeParams

例如,您可以从该路线获取产品的ID:

www.yoursite.com/product/id

通过做:

var id = $routeParams.id

在将参数传递给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>

现在,在您的角度控制器my_ctrl您可以通过访问您的值(ID) myID在你的控制器(my_ctrl):

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

请记住,Angular是双向数据绑定框架,因此,如果您更改模型中的值,则HTML会反映在JS上,如果您更改JS中的值,则会反映在View上。

暂无
暂无

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

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