我有几个存储在我的数据库中的博客。其中一些在html中有javascript计算器就像这个
<script type="text/javascript" src="http://www.financialsoccer.com/FinancialSoccer.js"></script>
我无法获得角度解析html并运行javascript。
因此,当它来自数据库时,它会被放入范围值并看起来像这样
$scope.article= '<h2> Financial Soccer</h2><script type="text/javascript" src="http://www.financialsoccer.com/FinancialSoccer.js"></script>'
我已经通过$ compile运行它来编译可能在博客中的任何指令,但javascript不会执行。
.directive('dynamicElement', ['$compile', function ($compile) {
return {
restrict: 'E',
scope: {
article: "="
},
replace: true,
link: function (scope, element, attrs) {
var template = $compile(scope.article)(scope);
element.replaceWith(template);
}
}
}])
有没有办法让这种情况发生?任何帮助将不胜感激。
谢谢!