I am having trouble with angularjs when after retrieving data from a rest service.
I am currently using the code from this SO question enter link description here to display my data.
myApp.directive('myTable', function () {
return {
restrict: 'E',
link: function (scope, element, attrs) {
var html = '<table>';
angular.forEach(scope[attrs.rows], function (row, index) {
html += '<tr><td>' + row.name + '</td></tr>';
if ('subrows' in row) {
angular.forEach(row.subrows, function (subrow, index) {
html += '<tr><td>' + subrow.name + '</td></tr>';
});
}
});
html += '</table>';
element.replaceWith(html)
}
}
});
To get data from my rest service, I use this code:
app.factory("Entry", function($resource) {
return $resource("/path/to/api:id");
});
app.controller("PostIndexCtrl", ['$scope', 'Entry', function($scope, Entry) {
$scope.entries =[];
Entry.query(function(data) {
$scope.entries = data;
});
}]);
I can retrieve the code data but for some reason, the in my html is not being updated after the data is received. It's as if the two way data binding is broken.
By the way, if I use ng-repeat on a list, it works.
This is what's on my html:
<my-table rows='entries'></my-table>