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

时间:2012-10-19 17:38:55

标签: javascript angularjs angularjs-ng-repeat angularjs-ng-show

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

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

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

enter image description here

以下是一些示例标记:

<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'
        }
    ]        

}

关于我可能做错的任何想法?

1 个答案:

答案 0 :(得分:36)

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

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

请参阅this fiddle了解ng-showng-repeat的工作样本。