0

I'm fairly new to AngularJS and I can't seem to find a way to do this appropriately. I created a custom directive to Apply a function a pass in the row Index. However, I can't seem to think of the way to show items in a row. What would be the best way to do this? I want to show specific and hide a target row via controller.

HTML:

<div class="row" data-index="{{$index}}">
   <div>other information</div>
   <div class="item hidden" ng-class="{hidden: hidden[{{$index}}]}">
         Item     
    </div>
</div>

My Directive:

 scope.$apply(function () {
     scope.$parent.showItem(index);
 });

Controller:

$scope.teamDrop = function(index) {
    $scope.hidden[index] = false;
};

1 Answer 1

2

You can use the ng-show and ng-hide directives to hide and show elements.

You can also use the ng-if directive to remove elements from the dom.

For your example I'd change your ng-class to an ng-hide

<div class="row" data-index="{{$index}}">
   <div>other information</div>
   <div class="item hidden" ng-hide="hidden[$index]">
         Item     
    </div>
</div>

You also don't need to use the {{}} syntax in the ng-class becausue it's already expecting an angular expression, that's for data binding.

Sign up to request clarification or add additional context in comments.

4 Comments

I am currently using directives, but I am trying to figure out how I can target a specific row.
I assumed your array contains a list of booleans
Do i have to declare an array of booleans or can I use !! ?
You can use any expression there which returns a boolean. Expressions are evaluated against the scope, so if your scope has a function shouldShow(index) you can use the result of that method call or you can simply compare a scope property to a literal value ($index % 2) == 1.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.