Filter with Angularjs and Gulp

Asked

Viewed 63 times

0

I’m creating a filter for the angular using the compiler Gulp however I am having an error and when analyzing the compiled code it seems that is compiling something wrong, what could be?

Filter:

class StrSplit extends Filter
  contructor: ->
    return (str, splitChar, splitIndex)->
      return '' unless str
      str.split(splitChar)[splitIndex]

View:

{{mystr | strSplit:',':0}}

Compiled filter:

StrSplit = (function() {
  function StrSplit() {}
  StrSplit.prototype.contructor = function() {
    return function(str, splitChar, splitIndex) {
      if (!str) {
        return '';
      }
      return str.split(splitChar)[splitIndex];
    };
  };
  return StrSplit;
})();
angular.module('ng-utils').filter('strSplit', [StrSplit]);

Error found:

Can’t Interpolate: 2 - {{text_filter | strSplit:',':0}} Typeerror: Cannot read Property 'apply' of Undefined

1 answer

1


It looks like "constructor" is incorrect.

class StrSplit extends Filter
  constructor: ->
    return (str, splitChar, splitIndex) ->
      return '' unless str
      str.split(splitChar)[splitIndex]
  • Thank you very much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.