Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
2
Reply
angular js service and factory
tri_inn
Apr 27 2017 4:35 AM
229
Reply
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'
);
});
}
});
2) explain with example for the difference between angular service and factory function ?
thanks
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
2
)
Next Recommended Forum
loading different area in page by angular
Why Unable to stop the SetInterval here? Approach is wrong