我最近一直在学习Angular JS,并且对基础知识有合理的把握,我已经看过其他的“How to Tos”和答案,但是我仍然无法将自己的头包裹在Custom Directives和使用$ scope。使用Angular自定义指令
我希望有人可以向我解释我出错的地方以及我应该用俗语说的话。
在此先感谢:
我想<tablerow></tablerow>
显示什么模板在$ scope.tabledata一切。
这里是对的jsfiddle链接 - 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>'
}
});