将动态变量设置为limitTo过滤angularjs

时间:2019-07-02 07:50:49

标签: angularjs limit truncate dynamic-variables

我想为limitTo过滤器添加动态变量。

<div ng-repeat="test in tests">
  {{(test.content | limitTo: strTestLimit[$index] || strTestLimit) + (test.content.length > strTestLimit ? '...' : '')}}
          <span ng-if="test.content.length > strTestLimit && test.content.length != strTestLimit[$index]">
              <button ng-click="showMore(test.content, $index)">Show more</button>
            </span>
            <span ng-if="test.content.length == strTestLimit[$index]">
              <button ng-click="showLess($index)">Show less</button>
            </span>
</div>
      scope.strTestLimit = 100

      scope.showMore = function(aa, index) {
        scope['strTestLimit'+index] = aa.length
      };

      scope.showLess = function(index) {
        scope['strTestLimit'+index] = 100;
      };

我不知道如何在HTML中使用limitTo:strTestLimit + $ index。

0 个答案:

没有答案