AngularJS - using ng-show within ng-repeat
Asked Answered
K

1

25

I'm having an issue using the ng-show directive within an ng-repeat block.

The boolean value does not seem to be getting passed to ng-show correctly...

To show what I mean, here is a screenshot of an example I made in JSFiddle:

enter image description here

Here is some example markup:

<table ng-controller="ActressController" class="table table-bordered table-striped">
    <tr ng-repeat="actress in actressList">
        <td>
            <span class="actress-name">{{ actress.name }}</span>
            <h4 ng-show="{ actress.name == 'Scarlett' }">Was in Avengers! <span class="note">(should only appear if Scarlett)</span></h4>
            <h2>{{ actress.name == 'Scarlett'}} <span class="note"><-- this statement is correct</span></h2>

        </td>

    </tr>
</table>

Here is an example controller:

function ActressController($scope) {
    $scope.actressList = [
        {
            name: "Angelina"
        }, {
            name: "Scarlett"
        }, {
            name: 'Mila'
        }, {
            name: 'Megan'
        }
    ]        

}

Any ideas on what I may be doing wrong?

Karinakarine answered 19/10, 2012 at 17:38 Comment(0)
A
37

In your ng-show you don't need { } try this:

<h4 ng-show="actress.name == 'Scarlett'">Was in Avengers! <span class="note">

See this fiddle for a working sample of an ng-show within an ng-repeat.

Arezzo answered 19/10, 2012 at 17:43 Comment(3)
Ahhh simple fix - from looking at the documentation it looked like the curly braces were required. Thanks!Karinakarine
@foozhan created a new fiddle showing ng-show within an ng-repeat. thanks for letting me know it was broken!Arezzo
Your fiddle is incorrect, as it loops the <ul>s not <il>s. Try this.Bilingual

© 2022 - 2024 — McMap. All rights reserved.