Hi I was working with angular directive and i have created one...
app.directive('customtable', function () {
return {
restrict: 'A',
require: 'ngModel',
link: function (scope, element, attrs) {
var html = '<table>';
angular.forEach(scope[attrs.rows], function (row, index) {
//html += '<tr><td>' + row.A+ '</td></tr>';
html += '<tr><td>' + row.B+ '</td>' +
'<td>' + row.C+ '</td>' +
'<td>' + row.D+ '</td>' +
'<td>' + row.E+ '</td>' +
'<td>' + row.F+ '</td>' +
'<td>' + row.G+ '</td>' +
'<td>' + row.H+ '</td></tr>';
if (index == 4) {
html += '<tr><td>' + 'Click Here to See All' + '</td></tr>';
}
})
html += '</table>';
element.replaceWith(html)
}
}
});
I am calling this directive from :
<table>
<tr customtable ng-model="data" rows="data" ng-hide="hideRows && $index > 4 && $index < (myArray.length - 5)">
</tr>
</table>
factory method :
dataFactory.getdate().success($scope.handleSuccess).then(function (result) {
$scope.data= result.data;
});
Here issue is As my scope variable $scope.data is getting set from factory method. first my directive code is getting executed and then the factory service gets called. so I am getting data variable undefined in directive code. any help and suggestions are most welcome. I am kind of stuck.
attrs.rowsyou are only seeing the text value "data". In the directive you don't have a two-way bind with the scope property.<tr>with a<table>?