Why is the inside function undefined in the AngularJS service?
.service('SliceService', function () {
var self = this;
var Slice = function(intervals, intervalSpan) {
self.activeSlice = [];
self.hasNext = true;
self.hasPrevious = false;
self.intervals = intervals;
self.intervalSpan = intervalSpan;
}
Slice.prototype.findIntervalIndex = function (time, slice) {
slice = slice || self.intervals;
return _.findIndex(slice, function (o) {
return o.time === time;
});
};
return Slice;
})
.controller('myController', ['SliceService', function(SliceService) {
SliceService([arr], 12);
SliceService.findINtervalIndex(time);
}])
When using it in a controller, the error
occurs.TypeError: Cannot set property 'activeSlice' of undefined
-
Update
Thank you, everyone! I have made changes to my example to better explain what I am trying to achieve. However, I am now encountering a
TypeError: SliceService.findIntervalIndex is not a function
. Maybe a service is not the best approach for my task?