I am trying to implement an AngularJS service that takes a date.prototype function and passes it to multiple controllers. I inject the services in the controllers but for some reason it isn't working. What am I doing wrong? Thanks.
services.js:
var appStuff = angular.module('services', [])
appStuff.service ('ChronService', function ()
{
Date.prototype.formatSubtractDate = function (x)
{
var myTime = new Date();
myTime.setFullYear(myTime.getFullYear) - x);
return myTime;
};
Date.prototype.formatAddDate = function (x)
{
var myTime = new Date();
myTime.setFullYear(myTime.getFullYear) + x);
return myTime;
};
});
oneController.js:
angular.module('oneController', [])
.controller('oneCtrl', function ($scope, ChronService) {
$scope.subtractYears = ChronService.Date().formatSubtractDate(4);
if ($scope.subtractYears >= 2004) {
console.log("right")
}
else
{
console.log("incorrect")
}
});
twoController.js
angular.module('oneController', [])
.controller('oneCtrl', function ($scope, ChronService) {
$scope.addYears = ChronService.Date().formatAddDate(25);
if ($scope.addYears < 1996) {
console.log("right")
}
else
{
console.log("incorrect")
}
});