2015-05-29 76 views
0

我试图显示基于品牌的产品,但ng-repeat内的ng-click不起作用。 但ng-click在ng-repeat之外工作正常。 ng-repeat内部有冲突吗?ng-click不能在ng-repeat内工作

模块

var myApp = angular.module('myapplication', ['ngRoute', 'ngResource','uiSlider']); 

我的视图

<a style="cursor:pointer" ng-click="Brandfilters = ''">All Brands</a> 

<div class="list-group-item" ng-repeat="product in products | unique: 'brand'" > 
    <a style="cursor:pointer" ng-click="Brandfilters='{{product.brand}}'">{{product.brand}}</a> 
</div> 

我的控制器

myApp.controller("StoreListCtr", ['$scope', '$http', '$resource', '$location', 
     function($scope, $http, $resource, $location) { 

     $scope.products = Products.query(); 
     $scope.Brandfilters = null; 
     $scope.lower_price = 100; 
     $scope.upper_price = 500; 

     $scope.priceRange = function(products) { 
      return (products['cost'] >= $scope.lower_price 
          && products['cost'] <=$scope.upper_price); 
     }; 
}]) 
+0

它应该充当产品在索引页上显示的过滤器... –

+0

如果我的解决方案无法正常工作,请尝试在重新生成时重现您的错误。以这种方式帮助你会更容易。 – Okazari

+0

你可以尝试用ng:repeat(product.brand)代替ng-repeat,并告诉我们它的行为如何? – Okazari

回答

0

刚刚尝试

<div class="list-group-item" ng-repeat="product in products | unique: 'brand'" > 
    <a style="cursor:pointer" ng-click="Brandfilters ='product.brand'">{{product.brand}}</a> 
</div> 
+0

无法正常工作....... –

+0

您的ng-repeat工作是否正常? – Vineet

+0

不,它不工作,它显示了一些像“Microsoft” –

0

在NG-重复的代码评估代码,这样你就不必使用{{}}。

<div class="list-group-item" ng-repeat="product in products | unique: 'brand'" > 
    <a style="cursor:pointer" ng-click="Brandfilters = product.brand">{{product.brand}}</a> 
</div> 
+0

嗨马蒂厄贝尔坦,我已经检查过,但它不工作... –

0

工作的例子 - http://plnkr.co/edit/DnTE05Vpo6erMgfpQQjo?p=preview

试试这个 -

替换 -

<a style="cursor:pointer" ng-click="Brandfilters='{{product.brand}}'">{{product.brand}}</a> 

随着

<a style="cursor:pointer" ng-click="setBrand(product.brand)">{{product.brand}}</a> 

并在控制器

$scope.setBrand = function(brandName) { 
     $scope.Brandfilters = brandName; 
} 
+0

这是为你工作吗? – User2

+0

不,它不工作.. –

+0

它为我工作。请检查 - http://plnkr.co/edit/DnTE05Vpo6erMgfpQQjo?p=preview – User2

0

您可能需要在模块中注入正确的指令,可能是'ui.directives',或者它可能是ui.utils

var myApp = angular.module('myapplication', 
           ['ngRoute', 'ngResource','uiSlider', 'ui.directives']); 

在看文档,您可能需要ui.utils ...

var myApp = angular.module('myapplication', 
           ['ngRoute', 'ngResource','uiSlider', 'ui.utils']); 

GitHub资源。