0

Does ng-repeat works inside ng-bind-html?

Where res2 is the StaticPage content. And res is a json file. Notice that I can get the variables from the scope (also print the json Array) but not possible to iterate with the ng-repeat.

Home Controller:

$rootScope.usefulContent = res;
$rootScope.staticContent = $interpolate(res2)($rootScope);

View:

<div ng-controller="homeCtrl" class="headerSize" id="staticPage">
<div ng-bind-html="staticContent"></div>
</div>

Static Page:

<div class="container content-home">
        <div class="row">
            <div class="col-sm-6">
                <div class="row">
                    <div class="col-xs-12">
                    <div ng-repeat="(key, value) in usefulContent | groupBy: 'Order'">
                        {{key}}
                    </div>
                    <ul class="list-group" data-ng-repeat="(key, value) in usefulContent | groupBy: 'Order'">
                        <li class="list-group-item">{{key}}
                            <ul class="list-group">
                                <li class="list-group-item child" data-ng-repeat="link in value">
                                    {{ link.SUBSECTION }}
                                </li>
                            </ul>
                        </li>
                    </ul>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                Col 2
            </div>
        </div>
    </div>

JSON:

[
  {
    "Order": 1,
    "SECTION": "HR",
    "SUBSECTION": "Administration",
  },
  {
    "Order": 1,
    "SECTION": "HR",
    "SUBSECTION": "Self Service",
  }
]

Thank you.

blas
  • 1
  • 1
  • Which ng-repeat is not working? – sudo May 31 '17 at 23:23
  • 2
    Also, can you post the JSON you are trying to iterate through? – sudo May 31 '17 at 23:25
  • Done, and both ng-repeat are not working – blas May 31 '17 at 23:47
  • You say both ng-repeat are working, there are 3 ng-repeat in your html – sudo May 31 '17 at 23:51
  • Can you post a static example of what you want your bootstrap `list-group` to look like? – sudo Jun 01 '17 at 00:02
  • not sure what you mean I posted it, the idea is to the StaticPage.html have it in a DB to be possible to edit it and avoid having to re publish de app None of the ng-repeat works, if I put a simple ng-repeat=[1,2,3,4], it doesnt work neither. But if I print some variable from the scope works, and for example if I use other directive like ng-if also works, but ng-repeat no case. – blas Jun 01 '17 at 12:09
  • what I meant was please include the expected output of what you want AFTER the `ng-repeat` has run. It's difficult to work out exactly what you want the page to look like. I'm confused because you have `ng-repeat="(key, value) in usefulContent`, then you are expecting key value pairs yet `usefulContent` is an array of objects so you will not get key value pairs you will get an object. – sudo Jun 02 '17 at 03:37

1 Answers1

0

Angular doesn't compile the html you included automatically. This post explains how to do it.

konst
  • 19
  • 6