【发布时间】:2016-08-04 14:38:40
【问题描述】:
我最近一直在学习 Angular JS,并且对基础知识有了合理的掌握,我在这里查看了其他“操作方法”和答案,但我仍然无法理解自定义指令并在其中使用 $scope他们。
我希望有人能以通俗的方式向我解释我哪里出了问题以及我应该做什么。
提前致谢:
我希望<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>'
}
});
【问题讨论】:
标签: angularjs angularjs-directive