【发布时间】:2017-08-04 10:11:35
【问题描述】:
我编译了一个字符串,但它并没有反映在 dom 上。
我有一些类似的字符串:
result = '<tr ng-click="someFun()" rowid="hh_'+gameId+'" id="hh_'+gameId+'" ng-class="game.currVideoReplay[' + gameId + '] ? \'active-current-hand\':\'\'">' + uCHtml + cCHtml + pTHtml + dCV +'</tr>';
result = $compile(result)($scope);
angular.element(document.querySelector("tbody")).html(result);
但它在 DOM 上显示如下:
<tbody class="hh-list">[[object HTMLTableRowElement]]</tbody>
问题是我如何在 DOM 中显示我的实际数据。
【问题讨论】:
-
你试过这个
$compile(result)($scope).html();吗?? -
您应该在模板中定义您的 html,并避免在您可以使用的代码中构建它
-
no @RameshRajendran 它不起作用,#devqon 我不能这样做,因为我的字符串来自服务器
-
请在调用 $compile 之前告诉我们 console.log(result) 返回什么
-
并尝试 element.find('tbody').append(result); (您可以在指令中将元素注入到您的链接函数中,如果它是控制器,则可以注入 $element
标签: javascript html angularjs angularjs-directive angularjs-scope