angular-underscore icon indicating copy to clipboard operation
angular-underscore copied to clipboard

Sorry but...

Open ProLoser opened this issue 12 years ago • 1 comments

You could just do:

myApp.filter('_', function(){
  return function() {
    var args = Array.prototype.slice.call(arguments, 0);
    var method = args.splice(1,1)[0];
    return _[method].apply(this, args);
  }
});
angular.forEach(_, function(method, name){
  // prefix all filters with '_' to prevent clobbering (such as $filter('filter') )
  myApp..filter('_'+name, function(){
    return method;
  });
});

Demo: http://plnkr.co/edit/Jq1Lg5v1GquxnqHe5hj2?p=preview

ProLoser avatar Mar 21 '13 04:03 ProLoser

Thank you for your advice, but not every underscore's method would be a proper filter, and some angular filter's use conventions could be merged with underscore, you could read the usage of filter in both angular and underscore, I have merged them together.

floydwch avatar Mar 21 '13 07:03 floydwch