angular
.module('erpos')
.service('GetBillNoService', ['$http', '$filter', '$cookies', function ($http, $filter, $cookies) {
return {
getData: function ($http, $filter, $cookies) {
var vm = this;
var billNo = "";
var date=$filter('date')(new Date(),'yyyy-MM-dd');
console.log(date);
date = date.split("-");
var curDate = date[0].substring(2, 4) + date[1].substring(0, 2);
HttpService
.get('/Company/' + $cookies.get('department') + '/MaterialNo/GetMax')
.success(function (data) {
switch (data.code) {
case 1000:
vm.materialIn = data.materialIn;
if (vm.materialIn == null) {
vm.billNo = curDate + "0001";
} else {
var time = vm.materialIn.maxBillNo.substring(0, 4).toString();
var maxmonth = time.substring(0, 4);
console.log(maxmonth);
if (maxmonth != curDate) {
vm.billNo = curDate + "0001";
}
else {
vm.billNo = (parseInt(vm.materialIn.maxBillNo) + 1).toString();
}
}
break;
}
});
billNo = vm.billNo;
console.log(billNo);
return billNo;
}
}
}]);
I want to get a billNo with this service,and then pass the billNo to the controller ,but errors appear that
'TypeError: Cannot read property 'get' of undefined'
I found the error in the 'get' is the property of cookies, but I have injected it already, so who can tell me what is going wrong?
HttpServiceisn't injected.success(). I highly suggest switching over to.then(). The first notation is deprecated and is completely removed in AngularJS version 1.6.0.