我想注入一個html,這是渲染Django模板的結果。 Django模板:AngularJS - 樣式不適用於附加的html
class CView(View):
def get(self, request):
return render_to_response('my_template.html', {},content_type="application/json")
當硬編碼時,生成的html正確顯示。 我想將接收到的html代碼注入到div中。問題在於自舉手風琴部件不顯示。我只拿到文字。
代碼在角控制器:
$scope.myHTML = '<div>Loading..<div>';
$scope.to_trusted = function (html_code) {
return $sce.trustAsHtml(html_code);
}
dataService.getMyHtml().success(function (data) {
$timeout(function() {
$scope.$apply(function() {
$scope.myHTML = data;
})
}, 0);
}).error();
HTML代碼:
<div ng-bind-html="to_trusted(myHTML)"></div>
MYHTML保持這樣的事情:
<div class="col-sm-3 col-md-2 sidebar">
<accordion close-others="true">
<accordion-group>
<accordion-heading>
Items One <i class="pull-right glyphicon"
ng-class="{'glyphicon-chevron-down': status.open, 'glyphicon-chevron-right': !status.open}"></i>
</accordion-heading>
<ul class="nav nav-sidebar">
<li><a href="#/one">One 1</a></li>
<li><a href="#/two">One 2</a></li>
</ul>
</accordion-group>
<accordion-group>
<accordion-heading>
Items Two <i class="pull-right glyphicon"
ng-class="{'glyphicon-chevron-down': status.open, 'glyphicon-chevron-right': !status.open}"></i>
</accordion-heading>
<ul class="nav nav-sidebar">
<li><a href="#/one">Two 1</a></li>
<li><a href="#/two">Two 2</a></li>
</ul>
</accordion-group>
</accordion>
</div>
上面的代碼只是呈現爲垂直列表菜單,但沒有手風琴。如果加載爲靜態html文件,則相同的代碼呈現效果很好。 我正在使用angular的bootstrap。