私は最近、Angular JSを学んでいて、基本について合理的な把握をしています。私は他のHow Tosと答えを見てきましたが、カスタムディレクティブとそれらの中に$ scopeを使用します。Angular Customディレクティブを使用する
私はどこに間違っていたのか、そして私がレイマンの言葉でやっているべきことを誰かに教えてくれることを願っています。事前に
ありがとう:
私は<tablerow></tablerow>
が$ scope.tabledata内のすべてのテンプレートに何があるか表示したいです。 tablerow
がtable
の有効な子要素ではないので、これが起こっているようだhttps://jsfiddle.net/paulhume/tt29411t/14/
var myApp = angular.module('myApplication', []);
myApp.controller('myController', ['$scope', function($scope) {
$scope.tabledata = [
{ cellone: 'One', celltwo: 'Two', cellthree: 'Three' },
{ cellone: 'One', celltwo: 'Two', cellthree: 'Three' },
{ cellone: 'One', celltwo: 'Two', cellthree: 'Three' },
{ cellone: 'One', celltwo: 'Two', cellthree: 'Three' },
{ cellone: 'One', celltwo: 'Two', cellthree: 'Three' },
{ cellone: 'One', celltwo: 'Two', cellthree: 'Three' },
{ cellone: 'One', celltwo: 'Two', cellthree: 'Three' },
{ cellone: 'One', celltwo: 'Two', cellthree: 'Three' },
{ cellone: 'One', celltwo: 'Two', cellthree: 'Three' }
];
}]);
myApp.directive('tablerow', function() {
return {
restrict: 'E',
scope: { 'rows': '=tabledata' },
template: '<tr ng-repeat="row in rows"><td>Cell One</td><td>Cell Two</td></tr>'
}
});