I am passing date
value to my custom filter this way:
angular.module('myapp').
filter('filterReceiptsForDate', function () {
return function (input, date) {
var out = _.filter(input, function (item) {
return moment(item.value.created).format('YYYY-MM-DD') == date;
});
return out;
}
});
I would like to inject a couple of scope variables there too, like what I can do in directives. Is that possible to do this without having to passing these vars explicitly as function arguments?
Apparently you can.
Usually you would pass scope variables to the filter as function parameter:
But, to pass the current scope in, you'd have to pass
this
:and
this
will be a reference to current scope:Simplified:
PLUNKER
Warning:
I found that
this
references local$scope
. Not sure if this is safe way of accessing it.