Angular js ng-class不在谷歌浏览器中工作但在firefox中工作

时间:2017-01-14 04:17:47

标签: angularjs google-chrome firefox

我是使用角度js的新手,我很困惑,我有这样的代码



angular.module("sportStore")
  .constant("productListActiveClass", "btn-primary")
  .controller("productListCtrl", function($scope, $filter, productListActiveClass) {

    var selectedCategory = null;

    $scope.selectCategory = function(newCategory) {
      selectedCategory = newCategory;
    }

    $scope.categoryFilterFn = function(product) {
      return selectedCategory == null ||
        product.category == selectedCategory;
    }

    $scope.getCategoryClass = function(category) {
      return selectedCategory == category ? productListActiveClass : "";
    }
  });

<div class="panel panel-default row" ng-controller="productListCtrl">
  <div class="col-xs-3">
    <a ng-click="selectCategory()" class="btn btn-block btn-default btn-lg">Home</a>
    <a ng-repeat="item in data.products | orderBy:'category' | unique: 'category'" ng-click="selectCategory(item.category)" class="btn btn-block btn-default btn-lg" ng-class="getCategoryClass(item.category)">
                    {{item.category}}</a>
  </div>
</div>
&#13;
&#13;
&#13;

然后当我尝试它时,导致chrome如下:

result in chrome

并在firefox中如下:

result on firefox

有人可以告诉我为什么会这样吗? ng-class在firefox上运行但不在chrome中运行。提前谢谢。

1 个答案:

答案 0 :(得分:1)

我发现之前必须清理chrome中的缓存。它现在在chrome中工作。