AngularJS - 在 ng-repeat 中使用 ng-show [英] AngularJS - using ng-show within ng-repeat

查看:34
本文介绍了AngularJS - 在 ng-repeat 中使用 ng-show的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

为了说明我的意思,这是我在 JSFiddle 中制作的示例的屏幕截图:

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

以下是一些示例标记:

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

这是一个示例控制器:

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

}

对我可能做错了什么有任何想法吗?

推荐答案

在你的 ng-show 你不需要 { } 试试这个:

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

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

请参阅 this fiddle 中的 ng-show 工作示例一个 ng-repeat.

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

这篇关于AngularJS - 在 ng-repeat 中使用 ng-show的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆