Reputation: 173
I have this AngularJS service and controller code.
angular.module('myModule', []).service("AttendanceService", function ($http) {
this.getdata = function () {
return $http({
method: "post",
url: "Dashboard/GetAttendanceReport",
params: [{ EmpID: $("#nameofEmp").val(), YearID: $("#YearIn").val() }],
dataType: "json"
});
};
}).controller('myController', function ($scope, AttendanceService) {
GetAlldata();
function GetAlldata()
{
var getAttendanceData = AttendanceService.getdata();
}
})
What I want is simply to call the above service i.e
return $http({
method: "post",
url: "Dashboard/GetAttendanceReport",
params: [{ EmpID: $("#nameofEmp").val(), YearID: $("#YearIn").val() }],
dataType: "json"
});
on button click
$("#btnLoad").click(function (event) {
});
Is it possible? I am very new to this...
Upvotes: 1
Views: 1463
Reputation: 2002
You need to change your factory like this :
angular.module('myModule', []).service("AttendanceService", function ($http) {
var fac = {};
fac.getdata = function () {
return $http({
method: "post",
url: "Dashboard/GetAttendanceReport",
params: [{ EmpID: $("#nameofEmp").val(), YearID: $("#YearIn").val() }],
dataType: "json"
});
};
return fac;
})
$("#btnLoad").click(function (event) {
AttendanceService.getdata();
});
Upvotes: 1