Hi,

I have a factory in which I need to parse a string of angularjs filter 
syntax. e.g. "date:'h:mma Z':'UTC'"
This string is actually defining angularjs filter name with its parameter 
and my controller I want to parse this string and invoke angulars $filter. 
But I am not sure whats the best way to achieve it. Here's my controller 
code.


angular.module ('app').factory ('Formatter', function ($filter, $compile) {
  var formatter = {
    formatValue: function (value, filter) {
      if (value) {
        if (filter) {
            /* filter here would be "date:'h:mma Z':'UTC'"
               I need to invoke here $filter('date')(param1, param2). So is it 
possible to use angular's native code?

               Another solution that I tried is to use 

               var elem = $compile("<div>{{ value | 
"+attrs.filter+"}}</div>")(scope)
               var formattedValue = elem.text();

               But this does not work.
            */
          return value;
        } else {
          return $filter('customFormatter')(value);
        }
      }
      return '';
    }
  };

  return formatter;
});



Is it possible to use Angular's native code, its parser to parse this 
string and invoke filter?  

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to