0

I am fairly new to angular and am trying to figure out why this wont work. I have an array of objects and within these objects there are keys and their values:

$scope.groups = [
        {
          title: 'Meal 1',
          content: 'Dynamic Group Body - 1',
          show: false
        },
        {
          title: 'Meal 2',
          content: 'Dynamic Group Body - 2',
          show: false
        }];

I have created a method that I want to loop over the array and change the 'show' boolean values to true. This is the body of this method:

for(var x = 0 ; x < 2; x++){
            $scope.groups[x].show = true;
        }

however it doesn't seem to work, and can't seem to understand why!. I am very new to angular so excuse my naivety with it all.

Could someone show me how to fix this?

5
  • Looks fine to me...where do you call that loop? Commented Dec 10, 2014 at 21:37
  • Its called when the user clicks a button - the idea is that the fucntion will loop through making all show values to true and therefore display the ng-show divs to the user Commented Dec 10, 2014 at 21:39
  • 1
    Do you have any errors in your console? Put a log statement to verify the method is being called. Commented Dec 10, 2014 at 21:40
  • Okay so it turns out, the loop is doing as it should do. However my issue is with the ng-show. This is the div: ng-repeat="group in groups" ng-show="{{group.show}}". After clicking the button that changes all show values to true it should then show all the group objects, however it doesnt Commented Dec 10, 2014 at 21:44
  • Ahh, there's the problem, ditch the {{}} in ng-show - I posted a quick answer. Commented Dec 10, 2014 at 21:46

1 Answer 1

1

ngShow is an Angular directive - you do not need the {{}} when passing conditions:

<div ng-repeat="group in groups" ng-show="group.show">
Sign up to request clarification or add additional context in comments.

Comments

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.