ng-repeat中的简单字符串操作

时间:2017-09-03 23:40:15

标签: angularjs

是否可以在ng-repeat中执行一些简单的字符串操作,并在ng-repeat元素之外显示结果,如下所示:

<span ng-repeat="f in fields" ng-init="result = '';">
    <span ng-init="result = result + f.name;"></span>
</span>

{{result}}

如何在整个操作过程中将'result'变量保持在同一范围内?

1 个答案:

答案 0 :(得分:-1)

管理解决问题。我只是把整个东西包裹在另一个跨度中:

<span ng-init="vars = {}; vars.result = '';">
    <span ng-repeat="f in fields">
        <span ng-init="vars.result = vars.result + f.name;"></span>
    </span>

    {{vars.result}}
</span>