0

I got this HTML:

<tr data-ng-repeat="report in reportSummary">
    <td class="reports-list-table-column-device-category" 
        data-ng-if="report.deviceCategory.length !== 1">
        <button popover="{{report.deviceCategory[0].name}}" 
        popover-title="Multi-category" type="button" class="btn btn-default">
             Multi-category
          </button>
   </td>
</tr>

and I want to iterate through report.deviceCategory[] in popover. How can I make it in HTML?

Anybody giving minus, justify it.

2
  • one more ng-repeat? ng-repeat="items in report.deviceCategory" Commented Sep 11, 2015 at 12:11
  • 1
    I want to iterate in my popover. Can you point a bit more clearly your idea? Commented Sep 11, 2015 at 12:14

3 Answers 3

1

You can try using a custom filter. <button popover="report.deviceCategory | customFilter">

Your filter would receive the the deviceCategory array, inside the filter just put your string together and return it. This way you avoid the 2nd ng-repeat and the the button repeating.

Angular Filters

angular.module('filters.module',[])
  .filter('customeFltr',function(){
    return function(input){
      _len = input.length;
      _output = '';
      for(var i=0;i<_len;i++)
        _output += input[i].name + ', ';
      _output = _output.substring(0,(_output.length - 2));
      return _output
    }
  }); // end filter.module

EDIT 3/2021

angular.module('filters.module', [])
  .filter('customFltr', () => {
    return function(input){
      return input.reduce((acc, val) => {
        return `${acc}, ${val.name}`
      }, '')
    }
  })
Sign up to request clarification or add additional context in comments.

Comments

0

just use $index

report.deviceCategory[$index].name

Update : you can do ng-repeat inside ng-repeat

<tr data-ng-repeat="report in reportSummary">
    <td class="reports-list-table-column-device-category" 
            data-ng-if="report.deviceCategory.length !== 1">
        <ul>
            <li ng-repeat="device in report.deviceCategory">
                <button popover="{{device.name}}" 
            popover-title="Multi-category" type="button" class="btn btn-default">
                 Multi-category
              </button>
            </li>
        </ul>
    </td>
</tr>

3 Comments

Nope, $index will give me only ng-repeat index, and what I need is yet another (from 0 to deviceCategory[n].length) index.
then you can do ng-repeat in ng-repeat.
That makes multiple buttons... and that is not what I need. I want iterated array deviceCategory in my popover="...".
0

If your popover allows templates, try this (as mentioned by STEVER):

<tr data-ng-repeat="report in reportSummary">
    <td class="reports-list-table-column-device-category" data-ng-if="report.deviceCategory.length !== 1">
        <button popover-template="template.html" popover-title="Multi-category" type="button" class="btn btn-default">
             Multi-category
        </button>
   </td>
</tr>

<script type="text/ng-template" id="template.html">
    <ul>
        <li data-ng-repeat="item in report.deviceCategory">{{item}}</li>
    </ul>
</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.