0

My 'top level' Angular file is thus: the module definition and two filters. I'm running angularJS with rails.

(function(){
  var app = angular.module('appname', ['Orders', 'TimePicker']);

  app.filter('money', function() {
    return function(input) {
      return input > 0 ? '£' + input : "FREE";
    };
  });

  app.filter('nodecimal', function() {
    return function(input) {
      input = parseInt(input)
      return input % 1 === 0 ? input.toFixed(0) : input.toFixed(2) ;
    };
  });
})();

It runs on development, but in production, I'm getting the following error: "Error: error:unpr Unknown Provider. Unknown provider: nodecimalFilterProvider <- nodecimalFilter".

From what I've read, this is because of minification.

I've attempted to follow the instructions on the page, for example, putting the functions of the filters in an inline dependence injection like so:

  app.filter('nodecimal', [function() {
    return function(input) {
      input = parseInt(input)
      return input % 1 === 0 ? input.toFixed(0) : input.toFixed(2) ;
    };
  }]);

But this didn't work. I've attempted to follow the instructions on the error page:

https://docs.angularjs.org/error/$injector/unpr?p0=nodecimalFilterProvider%20%3C-%20nodecimalFilter

and on this stack overflow question:

"Uncaught Error: [$injector:unpr]" with angular after deployment

I'm going to try the ngmin-rails gem, but I hate installing gems as they seem to cause as many problems as the fix.

Community
  • 1
  • 1
Will Taylor
  • 1,994
  • 2
  • 23
  • 36
  • as per the initial code you had pasted, issue shouldnt break because of minification. can you please create a plunkr with minified version. also share non-minified js file. – harishr Oct 29 '14 at 12:15
  • btw totally agree with `but I hate installing gems as they seem to cause as many problems as the fix.` – harishr Oct 29 '14 at 12:16
  • HarishR: Haha glad I'm not the only one! I've fixed it, I'll share the solution above. – Will Taylor Oct 29 '14 at 12:20

1 Answers1

0

Use the following process:

  • Install the ngannotate-rails gem

  • Delete your old cached assets and allow them to be rebuilt

  • Re-precompile any precompiled assets

  • Redeploy

References

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265