AngularJS - 在ng-repeat中使用ng-show

时间:2022-11-25 17:19:21

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

我在ng-repeat块中使用ng-show指令时遇到问题。

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

布尔值似乎没有正确传递给ng-show ...

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

为了表明我的意思,这里是我在JSFiddle中做的一个例子的截图:

AngularJS  - 在ng-repeat中使用ng-show

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 个解决方案

#1


36  

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

在您的ng-show中,您不需要{}试试这个:

<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.

有关ng-repeat中ng-show的工作样本,请参阅此小提琴。

#1


36  

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

在您的ng-show中,您不需要{}试试这个:

<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.

有关ng-repeat中ng-show的工作样本,请参阅此小提琴。