在angularjs中将html标记追加到$scope

在angularjs中将html标记追加到$scope,html,angularjs,Html,Angularjs,我想将html标记附加到id中的每个元素,并在文本框中显示它,如1x,2x,3x(x是使用×;的关闭按钮) 我正在使用以下代码 我的html标签 <input type="text" id="receiver" class="form-control input-sm" ng-model="to" /> Angularjs控制器 $scope.to=""; $scope.id=[1,2,3]; $scope.append = function ($event) {

我想将html标记附加到id中的每个元素,并在文本框中显示它,如
1x
2x
3x
x
是使用
×;的关闭按钮)

我正在使用以下代码

我的html标签

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

Angularjs控制器

$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>');
}
$scope.to=”“;
$scope.id=[1,2,3];
$scope.append=函数($event){
$scope.to=$scope.to+id[0]+(“×;”);
}
但我得到了以下结果:

1次
2次
3次


有人能帮我吗。

您的解决方案有两个问题:

  • 您希望提供一个HTML,但该HTML将被转义,并在最终输出中作为字符串处理/显示。为了防止HTML被转义,必须在
    ng model
    中使用
    ng bind HTML
    指令。不要忘记声明为模块依赖项
  • 您正试图在输入标记中包含HTML。这是不可能的,大多数浏览器都会从输入标签中删除HTML(使其成为同级而不是子级)。您必须重新设计要执行的操作,这样
    1x
    2x
    …的容器就不是
    输入

  • 我也面临着同样的问题,我认为你现在所做的是不可能的。您不能在输入标记中包含HTML。我希望HTML标记附加到$scope variable。您可以检查此链接是否有助于您。。。[链接]()你能在线显示你的代码吗。