AngularJS - 使用一个节目中之重(AngularJS - using ng-show w

2019-08-01 16:25发布

我使用的是NG重复块内的NG-显示指令有一个问题。

布尔值似乎并没有被获得通过正确NG-节目...

为了说明我的意思,这里是我的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'
        }
    ]        

}

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

Answer 1:

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

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

请参见本拨弄了的工作示例ng-show的内ng-repeat



文章来源: AngularJS - using ng-show within ng-repeat