因为我ng-bind-html用到了ng-click,需要用compile,但是我看的文档都是在directive里面写compile,问题是我是在过滤器filter里面用compile,怎么用啊,网上一点资源都找不到。
app.filter('httpClickFilter',function($sce){
return function(inputText){
var textHttpArray = inputText.split('http');
textHttpArray[textHttpArray.length-1] = textHttpArray[textHttpArray.length-1] + ' ';
for(var i = 1;i < textHttpArray.length; i++){
var textSubstring = 'http' + textHttpArray[i].substring(0,textHttpArray[i].indexOf(' '));
var replaceTextHttp = ""+textSubstring+"";
inputText = inputText.replace(textSubstring,replaceTextHttp);
}
return $sce.trustAsHtml(inputText);
}
})
HTML:
大体的意思是:拦截一段text字段,查找里面的http链接,把HTTP链接修改为可点击。这里使用过滤器没问题吧!
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号