私は2つのコントローラ、リンクのリストとテーブルtheadと空のtbodyを含むpageController.jsと、データを追加する指令を持つarticleController.jsを持っていますTBODYへのリンクは、ここに Angularjs別のコントローラから来るデータでng-repeatを追加する方法
がHTMLファイルである、をPagesControllerのthead要素内<div ng-controller='pageController as pg'>
<ul>
<li>
/* This table is dynamically appended */
<a href="" sample-directive>Click Me</a>
<table>
<thead>
<tr>
<th>Field1</th>
<th>Field2</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</li>
</ul>
</div>
articleController.js
をクリックしたときにテーブルのtbodyを投入する必要があり、このコントローラ
myApp.directive("sampleDirective", function($compile, $parse, $rootScope) {
return {
scope: {
id: "=",
status: "@"
},
link: function($scope, $element, $attrs) {
var clickingCallback = function() {
var $elem = $("#"+id);
$scope.articleData = [{"id":1076,"article_master_id":24,"article_name":"Testtest"},{"id":1077,"article_master_id":24,"article_name":"test2"},{"id":1078,"article_master_id":24,"article_name":"test3"}]; /* some data it has */
var output = angular.element("<tr ng-repeat='fld in entryC.articleData' ng-show='entryC.articleData.length'>"+
"<td>{{ fld.article_master_id }}</td>"+
"<td>{{ fld.article_name }}</td>"+
"<td>{{ fld.id }} {{ entryC.articleData }}</td></tr>");
$elem.empty();
$elem.append($compile(output)($scope));
}
$element.bind('click', clickingCallback);
}
}
<li><a sample-directive>
タグがPageControllerでに属し、このディレクティブがクリックされたとき、それは、articleController.js下
をリンクコールバック関数を実行します私は私の指示のコールバック関数をトリガすることができた、 問題基本的にはあなたのngのリピートは、テンプレート以来働いていなかった、それは文句を言わない実行を取得ng-repeat
されず、エラー、
ワーキングサンプルが高く評価されるだろう、ありがとう、
それは私が唯一それを動作させるために一緒に一度、すべてのそれをすべてをコンパイルする必要があることを意味するのでしょうか?ありがとうございました、! – apelidoko