如何改变ng-repeat中的值并显示ng-repeat

时间:2014-04-23 05:28:09

标签: angularjs

{{$$addFunc='isAdd'}}
<span ng-repeat="listItem in stmt.content">
    <span ng-switch on="listItem.meta.category">
        <span ng-switch-when="plain" ng-bind-template="{{listItem.content}}">
        </span>
        <span ng-switch-when="link">
            <a href="{{listItem.content.lnk}}">{{listItem.content.cap}}</a>
        </span>
        <span ng-switch-when="list" ng-init="{{$$addFunc='isInsert'}}">{{$$addFunc}}</span>
    </span>
</span>
{{$$addFunc}}

如何修改代码以使$$ addFunc为'isInsert'?

1 个答案:

答案 0 :(得分:0)

您不需要{{}}插值来设置变量的值。 ng-init采用简单的表达方式:

ng-init="$$addFunc='isInsert'"


您要更新$$addFunc的另一个问题是,ng-switch会创建child scope。因此,此范围可以更新$$addFunc,您应该将其移动到对象中:

$scope.operation = {
  $$addFunc: 'isAdd'
};

并按照以下方式更新:

<span ng-switch-when="list" ng-init="operation.$$addFunc='isInsert'">

这是一个有效的演示:http://plnkr.co/edit/Alypsqu1bSCwCqko4F8m?p=preview

相关问题