AngularJS - 后NG-结合HTML的运行定制指令 [英] AngularJS - Run custom directive after ng-bind-html

查看:77
本文介绍了AngularJS - 后NG-结合HTML的运行定制指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我想在的DOM运行一个自定义指令的情形 NG-绑定-HTML 创建。

I've a scenario which I want to run a custom directive on the DOM that ng-bind-htmlcreate.

Basicly我有自定义HTML标签的行为< A> ,因为这是加载HTML是不安全的,当用户点击我已经链接事情发生之前,jqLit​​e又名中,点击事件来执行某些功能。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆