TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
tri_inn
NA
1.2k
235.5k
angular js service and factory
Apr 27 2017 4:35 AM
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
Reply
Answers (
2
)
loading different area in page by angular
Why Unable to stop the SetInterval here? Approach is wrong