【发布时间】:2016-02-21 15:34:12
【问题描述】:
我想创建一个包含动态内容的表格。单击元素时,详细信息应显示在下一行中。所以我创建了以下内容:
<table ng-controller="TestCtrl">
<tr ng-repeat-start="word in ['A', 'B', 'C']">
<td><!-- Some Information, Image etc --></td>
<td ng-click="showDetails(word)">{{word}}</td>
</tr>
<!-- This is only visible if necessary -->
<tr ng-repeat-end ng-show="currentDetail == word">
<td colspan="2" ng-attr-id="{{'Details' + word}}"></td>
</tr>
</table>
我有以下js代码:
angular.module('maApp', []).controller("TestCtrl", function($scope, $document, $compile){
$scope.showDetails = function(word){
var target = $document.find("Details" + word);
//I checked it - target is NOT null here
//target.html("<div>Test</div>");
//target.append("<div>Test</div>");
var el = $compile("<div>Test</div>")($scope);
target.append(el);
//Show tr
$scope.currentDetail = word;
};
});
我也尝试了上面注释的解决方案,但没有任何效果(但是 tr 出现了)。我猜$document.find("Details" + word) 有问题,但我不知道是什么问题。
最终我想添加一个<iframe>,而源将包含word。
有人看到我在这里做错了吗?
【问题讨论】:
标签: javascript html angularjs dom add