AngularJS - 后NG-结合HTML的运行定制指令 [英] AngularJS - Run custom directive after ng-bind-html
问题描述
我有,我想在的DOM运行一个自定义指令的情形 NG-绑定-HTML
创建。
I've a scenario which I want to run a custom directive on the DOM that ng-bind-html
create.
Basicly我有自定义HTML标签的行为< A>
,因为这是加载HTML是不安全的,当用户点击我已经链接事情发生之前,jqLite又名中,点击
事件来执行某些功能。
Basicly I've to customize the behavior of the html tag <a>
because the html that is loading is unsafe and when the user click the link I've to execute some functions before anything happens, aka, the click
event of jqLite.
所以,我原来的IDEIA是创建修改任何&LT的行为指令;一个方式&gt;
,我把我的指令属性的容器内。
So my original ideia was create a directive that modifies the behavior of any <a>
inside the container that I put the attribute of my directive.
这工作得很好,直到我与 NG-绑定-HTML
相结合,我的指令运行前NG-绑定-HTML
编译字符串转换成HTML和附加到DOM。
This works fine, until I combine with ng-bind-html
, my directive runs before the ng-bind-html
compile the string into html and attached to the DOM.
那么,是没有办法的之后运行我的自定义指令NG绑定-HTML
运行?
So, is any way to run my custom directive after the ng-bind-html
run?
推荐答案
DEMO
HTML
<div ng-app="myApp" ng-controller="myCtrl">
<div ng-bind="sometext" my-directive>before</div>
</div>
控制器:
angular.module('myApp', []);
angular.module('myApp').controller('myCtrl', function($scope) {
$scope.sometext="stuff here";
});
指令:
angular.module('myApp').directive('myDirective', function() {
return {
priority: 10, // adjust this value ;)
link: function(scope,element,attrs) {
scope.$watch(attrs.ngBind, function(newvalue) {
console.log("element ",element.text());
});
}
};
});
使用优先级
内部指令属性毫克绑定后,运行code
Use priority
property inside directive to run your code after mg-bind
这篇关于AngularJS - 后NG-结合HTML的运行定制指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!