1

I want to find the solution for bind html in string example my string inside:

Hello this is text <a href="#">Kristoff</a> this is my domain www.website.com

Currently used: ng-bind-html="text | linky:'_blank' | but I wanted result like this

<a href="#">Kristoff</a> to Kristoff that bind href and www.website.com already bind by Angularjs

http://www.website.com/

What I want only bind href only.

3
  • 1
    read about $sce.trustAsHtml Commented Apr 21, 2017 at 8:35
  • 2
    Just rewrite you'r question. Its completely unreadable. What is is the output you get? and what is the output you want? You get <a href="#">Kristoff</a>? ... Commented Apr 21, 2017 at 8:35
  • ng-sanitize can be used. Commented Apr 21, 2017 at 8:41

1 Answer 1

1

DEMO

JS :

var myApp = angular.module('myApp',['ngSanitize']);

myApp.controller('MyCtrl',['$scope', function($scope) {
    $scope.htmlString = 'Hello this is text <a href="#">Kristoff</a> ' +
     'this is my domain <a href="http://www.website.com/">www.website.com</a>';

}]);

HTML :

<div ng-app="myApp" ng-controller="MyCtrl">
  <p ng-bind-html="htmlString"></p>
</div>
Sign up to request clarification or add additional context in comments.

2 Comments

if I added <h1>Hello me</h1 it still bind to normal I don't want to bind any html just only href for security reason.
Then you have to split your string and apply the ng-bind only on <a> element.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.