1

I want to append html tag to every element in id and show it in text box like 1 x,2 x,3 x.(x is close button using ×)

I am using the following code.

My html tag

<input type="text" id="receiver" class="form-control input-sm" ng-model="to" />

Angularjs controller

$scope.to="";
$scope.id=[1,2,3];
$scope.append = function ($event) {
      $scope.to=$scope.to+id[0]+('<div class="close" data-dismiss="modal">&times;</div>');
}

But I am getting following output :

1 <div class="close" data-dismiss="modal">&times;</div>,2<div class="close" data-dismiss="modal">&times;</div>,3<div class="close" data-dismiss="modal">&times;</div>

Can any one help me.

5
  • i am also facing the same problem. Commented Feb 24, 2016 at 5:43
  • 1
    I don't think its possible to do what you are doing. You cannot have HTML inside an Input tag. Commented Feb 24, 2016 at 6:28
  • here i want html tag append to $scope variable Commented Feb 24, 2016 at 6:31
  • can you check whether this linke helps you... [Link] (stackoverflow.com/questions/14242531/…) Commented Feb 24, 2016 at 7:57
  • Could you show up your code online. Commented Feb 24, 2016 at 8:25

1 Answer 1

1

You have two issues with your solutions:

  1. You want to provide an HTML, but this HTML is escaped and treated/displayed as a string in your final output. In order to prevent the HTML from being escaped, you have to use the ng-bind-html directive inside of ng-model. Don't forget to declare ngSanitize as a module dependency.
  2. You are trying to include HTML inside an input tag. This won't be possible and most browsers will get this HTML out of the input tag (making it a sibling rather than a child). You have to redesign what you want to do, so the container of 1 x, 2 x...is not an input.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.