こんにちは、私はAngularJsディレクティブからテーブルを返してバインドしようとしています。AngularJsディレクティブがテンプレートデータを返す前にレンダリングする
私の角度のコードは次のとおりです。
function directive($window, employeeDataServices) {
var directive = {
link: link,
restrict: 'EA',
renderOnFirstLoad: false,
template: myData()
};
return directive;
function link(scope, element, attrs) {
}
function myData() {
angular.element(document).ready(function() {
employeeDataServices.getEmployees().then(function (response) {
var table = "<table>";
table += "<tr>";
table += "<th>Id</th>";
table += "<th>Name</th>";
table += "</tr>";
angular.forEach(response, function (value, key) {
table += "<tr>";
table += "<td>" + value.Id + "</td>";
table += "<td>" + value.Name + "</td>";
table += "</tr>";
});
table += "</table>";
return table;
});
});
}
}
とHTMLで私はあなたが要求を行っているのでAngularJsディレクティブは、HTMLバインド
ええ、そうではありません、それはangularjsの使用方法ではありません。そして、あなたは非同期を理解していません。テンプレートは完全に静的なHTMLの部分です。テンプレート内でng-repeatなどを使用して角度式を使用し、データにバインドすることで動的にします。しばらくの間、ディレクティブを忘れて、基本的なコントローラーとビューについて学んでください。 –