复制$ sce创建的对象并修改其值

时间:2017-01-02 13:08:27

标签: javascript jquery angularjs

我有一个变量,如下所示: -

tableData1[$scope.tableHeadingsConstant[0]] = $sce.trustAsHtml('<div class="header12" id="runTitle0" style="cursor: pointer;">'
                     + counter++ + '</div>')

现在我要复制它,打开它,更改div的值然后再重新包装。

有可能吗?

1 个答案:

答案 0 :(得分:1)

您可以使用$sce.getTrustedHtml获取原始值。

例如:

$scope.value1 = $sce.trustAsHtml('<div>1</div>');

var unwrapped = $sce.getTrustedHtml($scope.value1);

unwrapped = unwrapped.replace('1', '2');

$scope.value2 = $sce.trustAsHtml(unwrapped);