实际上,我得到了一个产品列表,我希望在点击ng-href时传递当前的产品ID,这要归功于ng-href中的ng-click功能。
这是我的html文件:
<div class="agile_top_brands_grids" ng-model="products" ng-repeat="product in products">
<div class="col-md-4 top_brand_left">
<div class="hover14 column">
<div class="agile_top_brand_left_grid">
<div class="agile_top_brand_left_grid_pos">
<img src="../../resources/images/offer.png" alt=" "
class="img-responsive" />
</div>
<div class="agile_top_brand_left_grid1">
<figure>
<div class="snipcart-item block">
<div class="snipcart-thumb">
<a ng-href="/#/singleproduct"
ng-click="currentProductId(product.id)">
<img src="../../resources/images/hh4.png">
</a>
<p>{{product.name}}</p>
<h4>{{product.price}}</h4>
</div>
</div>
</figure>
</div>
</div>
</div>
</div>
我试图在我的控制器中获取这样的ID:
$scope.currentProductId = function (productId) {
console.log("Hello");
console.log(productId)
}
但$ scope.currentProductID根本没有执行..
请问好吗?
答案 0 :(得分:0)
你好,有一些混乱,比如
<div class="agile_top_brands_grids" ng-model="products" ng-repeat="product in products">
<div class="col-md-4 top_brand_left">
<div class="hover14 column">
<div class="agile_top_brand_left_grid">
<div class="agile_top_brand_left_grid_pos">
<img src="../../resources/images/offer.png" alt=" " class="img-responsive" />
</div>
<div class="agile_top_brand_left_grid1">
<figure>
<div class="snipcart-item block" >
<div class="snipcart-thumb" >
<a ng-href="/#/singleproduct" ng-click="currentProductId(product.id)"><img src="../../resources/images/hh4.png"></a>
<p>{{product.name}}</p>
<h4>{{product.price}}</h4>
</div>
</div>
</figure>
</div>
</div>
</div>
</div>
解决方案1是:您可以在href中传递id,如
ng-href =“/#/ singleproduct”+ product.id并删除ng-click功能
解决方案2是:ng-href =“#”并使用ng-click功能进行更改路线。