AngularJS - 在<code> element

时间:2016-08-31 12:05:35

标签: javascript html angularjs angularjs-ng-repeat angularjs-ng-include

I have a json array that I iterate through like so...

<div class="panel panel-primary" ng-repeat="c in components">
    <div class="panel-body">
        <h2>{{c.title}}</h2>
        <div ng-include="c.template"></div>
    </div>
</div>

The ng-include loads the html template file, i.e. 'components/blockquote.html'

Is there a way to also load the source code from that html file as well, so you can show the component next to the source in an element like so..

<div class="panel panel-primary" ng-repeat="c in components">
    <div class="panel-body">
        <h2>{{c.title}}</h2>
        <div ng-include="c.template"></div>
        <code>
          <blockquote>
            <p>This text is quoted.
          </blockquote>
        </code>
    </div>
</div>

1 个答案:

答案 0 :(得分:0)

由于你知道模板url,你可以使用AJAX加载它,就像加载任何其他(例如json)资源一样。然后你可以简单地在模板中显示它并显示实际的html代码,因为默认情况下它会被视为不安全的html。