Why Angular PostFix fails after minification as a module?

639 views
Skip to first unread message

Andre Venter

unread,
Mar 6, 2014, 2:31:00 AM3/6/14
to ang...@googlegroups.com
I am new at AngularJS and just learned that minification only works if you take precautions.

It suggests a number of formats which all have "[" and "]" in specific locations to over come the effects of minification.

I am using this generator for my project - https://github.com/cgross/generator-cg-angular - it does the minification as part of the grunt build.

When I try to fix POST to work with Apache, it does not pass minification (as described here: http://victorblog.com/2012/12/20/make-angularjs-http-service-behave-like-jquery-ajax/)

My version of the code is this:
http://jsbin.com/wojac/2/edit?js

It works fine when I run the project, but when I build and minify it fails.

The error I get is:
Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to: Error: [$injector:modulerr] Failed to instantiate module httpPostFix due to: Error: [$injector:unpr] Unknown provider: a http://errors.angularjs.org/1.2.15-build.2365+sha...<omitted>...0)

It seems that the module itself is not minification proof.

Surely I am not the first person to try and alter Post using this technique and expecting the minified result to work.

Andre Venter

unread,
Mar 6, 2014, 4:00:18 AM3/6/14
to ang...@googlegroups.com


I am using this generator for my project - https://github.com/cgross/generator-cg-angular - it does the minification as part of the grunt build.


According to the docs the this generator uses grunt-ngmin  - https://github.com/btford/grunt-ngmin
And according to its docs, there should be no issue with minifying.

I guess the question is: Why is grunt-ngmin failing to minify http://jsbin.com/wojac/2/edit?js correctly?

Sander Elias

unread,
Mar 6, 2014, 4:40:06 AM3/6/14
to ang...@googlegroups.com

Hi Andre,

this line: angular.module('httpPostFix', [], function($httpProvider) wilt get translated into angular.module('httpPostFix', [], function(a)
Angular does not have an a-Provider,so you get an error.
You need an prefix tool in your grunt file, or manually make sure you have prepared your code for minification.
in this case it should look like:
angular.module('httpPostFix', [], ['$httpProvider',function($httpProvider)
and of course close the array right after your function ends.

Hope this makes sense to you,
Regards
Sander

Sander Elias

unread,
Mar 6, 2014, 4:43:06 AM3/6/14
to ang...@googlegroups.com
Just saw you additional remark,

My guess (and its not more then just that!), the code of ngmin does not take in account using the 3rth parameter of ng-module.

Regards
Sander

Andre Venter

unread,
Mar 6, 2014, 5:12:07 AM3/6/14
to ang...@googlegroups.com
Thank you so much Sander.

That worked like a charm!

angular.module('httpPostFix', [], ['$httpProvider',function($httpProvider) - with the matching closing "]"
Reply all
Reply to author
Forward
0 new messages