$ http响应中的Angular指令 [英] Angular directives in $http response
问题描述
角度1.5
我的$ http数据服务也返回带有指令的html编码文本,例如ng-click文本.
My $http data service returns html encoded text with directives too, like ng-click in the text.
我需要显示html并激活ng-click指令.
I need to display the html and have the ng-click directives get activated.
要显示我正在执行的操作,它可以工作,但是ng-clicks不起作用:
To display I am doing this and it works, but ng-clicks don't work:
<div class="mt10" ng-repeat="row in aqdas.Paragraphs" ng-cloak>
<span ng-bind-html="TrustDangerousSnippet(row.Text)" >
{{row.Text}}
</span>
</div>
这是TrustDangerousSnippet:
Here is TrustDangerousSnippet:
$scope.TrustDangerousSnippet = function (text) {
var val = $sce.trustAsHtml(text);
return val;
};
我该如何编辑TrustDangerousSnippet,以便一旦$ http下载代码后就可以打开文本中的ng-click?
How can I edit TrustDangerousSnippet so that the ng-click's in the text are turned on once $http downloads the code?
推荐答案
此指令也可与您的代码一起使用.绑定指令中的html元素,请使用complie.它会工作..
Use this Directive also with your code. to bind html element in directive use complie. it will work..
.directive('compile', ['$compile', function ($compile) {
return function(scope, element, attrs) {
scope.$watch(
function(scope) {
return scope.$eval(attrs.compile);
},
function(value) {
element.html(value);
$compile(element.contents())(scope);
}
);
};
}])
这篇关于$ http响应中的Angular指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!