2017-04-26 95 views
0

我有一个产品页面,其中显示了数据库中的产品。该产品页面的代码。无法从角度js中的URL获取参数并将其传递给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 --> 

现在的问题是,我想在产品上点击时在不同的页面编辑特定的产品。我在URL中传递了这个id。但我无法从控制器调用url参数,同时将参数传递给一个php文件,以便我可以从数据库调用数据。

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

+0

在PHP上使用$ _GET获取url参数,并在隐藏输入字段中将此值用作值。对于那个输入字段定义ng模型,ng模型会给你角JS的值。另一种方法是使用角度“位置”。 – webDev

回答

0

为了让你可以使用URL PARAM:$ routeParams

例如,你可以从该路由产品的ID:

www.yoursite.com/product/id

这样做:

var id = $routeParams.id 
0

在你的HTML/PHP页面你通过PARAM后的URL 假设你的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您可以通过使用 myID 在你的控制器(my_ctrl)来访问你的价值(ID):

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

记住角既是双向数据绑定框架,因此,如果你改变了你的模型的值,那么HTML会反映到JS上,如果你改变了JS的值,它将反映在View上。

相关问题