So, I saw an example when they passed an angular postponed to ngRepeat, and it worked fine. For some reason, when I set up this example, it does not work. Can someone tell me why? If you assign data without delay, then this works fine, i.e. $scope.objects = [{id:1}...]
Many thanks
Spell here
<!doctype html> <html ng-app="app"> <head> </head> <body> <testlist/> <script src="/lib/angular/angular.js"></script> <script> var app = angular.module('app', []); app.factory('dataService', function ($q) { return { getData : function () { var deferred = $q.defer(); setTimeout(function () { deferred.resolve([{id:1},{id:2},{id:3},{id:4}]); },0); return deferred.promise; } }; }); app.directive('testlist', ['dataService', function(dataService) { return { restrict: 'E', replace: true, scope : {}, template: '<div ng-repeat="data in objects">{{inspect(data)}}{{data.id}}</div>', controller: function($scope) { $scope.objects = [{id:1},{id:2},{id:3},{id:4}]; $scope.inspect = function (obj) { console.log(obj) } } } }]); </script> </body> </html>
angularjs
screenm0nkey
source share