2017-04-26 61 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上。

相關問題