显示基于点击类别角度js的隐藏类别

时间:2017-12-28 07:01:04

标签: javascript angularjs

我想根据所选类别显示和隐藏子类别。 两者都来自后端的动态 但出了点问题。 这是我的代码: -

<div class="expense-categories">
    <div class="row">
        <div class="col-md-2 col-sm-6 col-xs-6 category_id" ng-repeat="category in mExpenseCategories">
            <a href="javascript:void()" ng-click="setActiveCategory(category)">
                <div class={{category.class}} ng-class="{active : activeCategory === category}">
                    <img src={{category.image}} alt="">
                    <p>{{category.name}}</p>
                </div>
            </a>
        </div>
        <div class="col-md-10 col-sm-6 col-xs-12 sub-category-none">
            <ul class="sub-category-menu animated fadeInLeft">
                <li><a class="category-back btn btn-fab btn-inverse btn-raised" href="javascript:void()"><i class="material-icons">arrow_back</i></a></li>
                <li><a class="well" href="javascript:void()">ab</a></li>
                <li><a class="well" href="javascript:void()">ab</a></li>
                <li><a class="well" href="javascript:void()">ab</a></li>
                <li><a class="well" href="javascript:void()">ab</a></li>
            </ul>
        </div>
    </div>
</div>

控制器代码: -

$scope.setActiveCategory = function(category) {
  $scope.activeCategory = category;
  $scope.showCategory = category;
  $scope.show = category.id;
  var mySelectedCategory = angular.element(document.querySelector('.category_id'));
  mySelectedCategory.hide();
  mySelectedCategory.addClass('display-category');
  var subCategory = angular.element(document.querySelector('.sub-category-none'));
  subCategory.show();
};

$scope.selectedSubcategory = function() {
  var subCategory = angular.element(document.querySelector('.sub-category-none'));
  subCategory.hide();
  var myCategory = angular.element(document.querySelector('.category_id'));
  myCategory.removeClass("display-category");
};

类别和子类别的JSON: -

[{id: 1, name: "cat_1"},{id: 1, name: "cat_2"}]

1 个答案:

答案 0 :(得分:1)

这种情况可能有助于“{active:activeCategory.id == category.id}”

onClick="editdetails(\''+ DatabaseName +'\')"