在文本输入中查找链接并将其转换为angularjs中的html链接

时间:2021-06-28 03:52:17

I want to find the links in text input and turns them into html links in angularjs.Here is my code but its not working. Html

我想在文本输入中找到链接并将它们转换为angularjs中的html链接。这是我的代码,但它不起作用。 HTML

<div class="item item-body" ng-bind-html="{{deal.notification_details}} | linky" >
</div>  

controller.js

 $scope.deal=[{id:'0',notification_details:'sample description http://www/example.com'}];

2 个解决方案

#1


1  

I think it should be:

我认为它应该是:

<div class="item item-body" ng-bind-html="deal.notification_details | linky"></div>

ngBindHtml expects an expression, hence you don't have to use interpolation markers {{ ... }}.

ngBindHtml需要一个表达式,因此您不必使用插值标记{{...}}。

To open a link in new tab you would use target setting of the linky filter:

要在新选项卡中打开链接,您将使用linky过滤器的目标设置:

ng-bind-html="deal.notification_details | linky:'_blank'"

#2


1  

$scope.deal it is json object so get first array item is start from 0

$ scope.deal它是json对象所以get第一个数组项是从0开始

<div class="item item-body" ng-bind-html="deal[0].notification_details | linky"></div> 

DEMO

#1


1  

I think it should be:

我认为它应该是:

<div class="item item-body" ng-bind-html="deal.notification_details | linky"></div>

ngBindHtml expects an expression, hence you don't have to use interpolation markers {{ ... }}.

ngBindHtml需要一个表达式,因此您不必使用插值标记{{...}}。

To open a link in new tab you would use target setting of the linky filter:

要在新选项卡中打开链接,您将使用linky过滤器的目标设置:

ng-bind-html="deal.notification_details | linky:'_blank'"

#2


1  

$scope.deal it is json object so get first array item is start from 0

$ scope.deal它是json对象所以get第一个数组项是从0开始

<div class="item item-body" ng-bind-html="deal[0].notification_details | linky"></div> 

DEMO