AngularJS - using ng-show within ng-repeat

試著忘記壹切 提交于 2019-12-20 11:13:10

问题


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:

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?


回答1:


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.



来源:https://stackoverflow.com/questions/12979532/angularjs-using-ng-show-within-ng-repeat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!