This is my code:
.filter(\'getUserName\', function(User) {
return function(id) {
User.get({ _id: id }, function(user) {
return user.name;
This is a terrible fit for a filter, but just as an intellectual exercise, you could have the filter return some default behavior (i.e. return blank) until data is fetched, and once fetched apply the filter. This would necessitate the filter to be $stateful
, which is very wasteful - it will run on every digest cycle.
app.filter("foo", function($timeout){
var cache = {};
function genFoo(input){
$timeout(function(){
cache[input] = input + "foo!";
}, 1000);
}
var filter = function(input){
if (input in cache) return cache[input];
genFoo(input);
return "";
};
filter.$stateful = true;
return filter;
});
Plunker
DO NOT do this as a filter :)