1) i have seen people use many time use service to call web service to fetch data. rarely people use factory function to to call web service to fetch data......why?
why people prefer service than factory function ?
here i am posting a sample service which is calling web service.
- app.service("TopMenuService", function ($http) {
- this.getTopMenu = function () {
- debugger;
- return $http.get("/employee/getTopMenu");
- };
- });
- app.service("LeftMenuService", function ($http) {
- this.getLeftMenu = function () {
- debugger;
- return $http.get("/employee/getLeftMenu");
- };
- });
- app.controller("EmpCtrl", function ($scope, TopMenuService,LeftMenuService) {
- GetTopMenu();
- GetLeftMenu();
- function GetTopMenu() {
- debugger;
- var _getTopMenu = EmployeeService.getTopMenu();
- _getTopMenu.then(function (topmenu) {
- $scope.topmenu = topmenu.data;
- }, function () {
- alert('Data not found');
- });
- }
- function GetLeftMenu() {
- debugger;
- var _getLeftMenu = EmployeeService.getLeftMenu();
- _getLeftMenu.then(function (leftmenu) {
- $scope.leftmenu = leftmenu.data;
- }, function () {
- alert('Data not found');
- });
- }
- });
thanks
Posted Apr 30, 2017, 3:41 PM
Bharath PeggemPosted Apr 28, 2017, 3:10 AM