Ich habe vor kurzem Angular JS gelernt und habe ein vernünftiges Verständnis für die Grundlagen, ich habe andere 'How tos' und Antworten hier angesehen, aber ich kann immer noch nicht meinen Kopf um benutzerdefinierte Richtlinien und Verwenden von $ scope in ihnen.Using Angular Custom Direktiven
Ich hoffe, dass jemand mir erklären kann, wo ich falsch gelaufen bin und was ich unter Laien machen sollte.
Vielen Dank im Voraus:
Ich mag <tablerow></tablerow>
zeigen, was alles in $ scope.tabledata in der Vorlage ist. Hier
ist ein Link auf die 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>'
}
});