3
Я хочу загрузить динамический контент через угловые (HTML, CSS, JS). Я использую директиву для динамического загрузки HTML.Загрузить js-скрипт или js-код динамически в угловом
app.directive("bindCompiledHtml", function($compile, $timeout) {
return {
template: '<div></div>',
scope: {
rawHtml: '=bindCompiledHtml'
},
link: function(scope, elem, attrs) {
scope.$watch('rawHtml', function(value) {
if (!value) return;
// we want to use the scope OUTSIDE of this directive
// (which itself is an isolate scope).
var newElem = $compile(value)(scope.$parent);
elem.contents().remove();
elem.append(newElem);
});
}
};
});
<div bind-compiled-html="content"></div>
Если контент содержит только HTML, он отображает его успешно, но если он содержит CSS/Script, это не так.
Вышеуказанная директива не отображает этот ниже код.
'<link rel="stylesheet" href="/static/engine/css/jquery.bxslider.less"><script src="/static/engine/js/jquery.bxslider.js"></script><style></style><script type="text/javascript">function mytest(){$(\'.bxslider\').bxSlider(); }</script><ul class="bxslider"><li ng-repeat=\'brainfact in brainfacts\'><img src="{$ brainfact.content[\'image\'] $}" /></li></ul>'
Окажу это ниже код:
'<ul class="bxslider"><li ng-repeat=\'brainfact in brainfacts\'><img src="{$ brainfact.content[\'image\'] $}" /></li></ul>'
демо plunker - http://plnkr.co/edit/QG5IbaNfhNDrIyRbXEGx?p=preview
Что такое прецедент? Потому что мне кажется, что это плохой дизайн ... – deostroll
@deostroll [здесь] (http://stackoverflow.com/questions/30521546/made-angular-scope-available-in-django-templateresponse?noredirect11 # comment49117361_30521546) - это полный поток, который я пытаюсь сделать – saf