angularjs - Using Restangular in the App using the factory -
i have created here working demoapp in have used restangular
it working fine when tired implement demoapp factory data doesnt seem come , cant check out possible bug in
/* file containing json object*/ [ {"id":1, "subject":"#aashima" }, {"id":2, "subject":"#aansh" }, {"id":3, "subject":"#artle" }, {"id":4, "subject":"#harish" } ]
<!doctype html > <html ng-app="app"> <head> <meta charset="utf-8"> <title>restangular</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.16/angular.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/restangular/1.5.1/restangular.min.js"></script> </head> <body> <div ng-controller="indexctrl omega" ng-cloak> <ul> <li ng-repeat="result in omega.people"> <span ng-bind="result.subject"></span> </li> </ul> <span ng-bind="omega.harish"></span> </div> <script> var app = angular.module('app', ['restangular']) app.config(function(restangularprovider) { restangularprovider.setbaseurl("\js"); app.controller('indexctrl', function( testfactory) { var self=this; testfactory.getfriendlist.then(function (homefriends) { self.people=homefriends; console.log(self.people); }); }); app.factory('testfactory', ['restangular', function (restangular) { return { getfriendlist: restangular.all('emp.json').getlist() } }]); </script> </body> </html>
<!doctype html > <html ng-app="app"> <head> <meta charset="utf-8"> <title>restangular</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.16/angular.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/restangular/1.5.1/restangular.min.js"></script> </head> <body> <div ng-controller="indexctrl omega" ng-cloak> <ul> <li ng-repeat="result in omega.people"> <span ng-bind="result.subject"></span> </li> </ul> <span ng-bind="omega.harish"></span> </div> <script> var app = angular.module('app', ['restangular']) app.config(function(restangularprovider) { restangularprovider.setbaseurl("\js"); }); app.controller('indexctrl', function( restangular, testfactory) { var self=this; restangular.all('evm.json').getlist().then(function(result) { self.people = result; }); testfactory.getfriendlist.then(function (homefriends) { console.log(self.people); self.people=homefriends; }); }); app.factory('testfactory', ['restangular', function (restangular) { return { getfriendlist: restangular.all('emp.json').getlist() } }]);
</script>
their syntax issue , have corrected , app run
Comments
Post a Comment