In the scenario I'm currently facing, I am working on creating a common reusable table structure using a directive. The goal is to display different JSON data in both the table header and body.
Below is the controller code:
angular.module('plunker', []);
function MainCtrl($scope) {
$scope.firstJson=[{name:"abc1",empid:10215},{name:"abc2",empid:10216},{name:"abc3",empid:10217},{name:"abc4",empid:10218},{name:"abc5",empid:10219}];
$scope.secondJson= [{product: "mobile", price: "10000"}, {product: "camera", price: "12000"}];
$scope.name = $scope.firstJson;
$scope.tableHeading=["heading1","heading2","heading3"];
$scope.toggle=true;
}
The directive code is as follows:
angular.module('plunker').directive('sampleDirective', function(){
return {
restrict: 'A',
scope: {
name: '=',
tableHeading:'='
},
templateUrl: 'reverse_template.html',
replace: true,
};
});
To see a demo of this directive in action, you can visit the following Plunker link: Demo
Here are the final outputs for the firstJson and secondJson respectively: https://i.stack.imgur.com/XOnni.png, https://i.stack.imgur.com/AtgXU.png
Any assistance on this matter would be greatly appreciated.