-
Notifications
You must be signed in to change notification settings - Fork 343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AngularJS automatic dependency injection broken upon update. #418
Comments
Hey, thanks for opening an issue. (Also thanks for the Fira system font patcher, I’m using it right now!) Would you mind explaining this a little more? Is this expected for any reason or something that happens with certain minification approaches and Angular? Also, are you writing your code with CoffeeScript? Thanks! |
Yes, I am using CoffeeScript. By the way I did not create the Fira font patcher; just the Yosemite Angular has a dependency injection mechanism. In Angular, we can declare dependencies for our controllers and services by declaring it using argument name: angular.module 'app', []
.controller 'MyController', ($scope, $http, myService) ->
# $scope is automatically injected by Angular
# $http is automatically injected by Angular
# myService is automatically injected by Angular Here, when a MyController instance is created, Angular would parse the function arguments' names, and inject the appropriate object. When code is minified, these parameter names become One workaround is to use an annotated function declaration, which can safely be minified: angular.module 'app', []
.controller 'MyController', [
'$scope', '$http', 'myService',
($scope, $http, myService) ->
# $scope is automatically injected by Angular
# $http is automatically injected by Angular
# myService is automatically injected by Angular
] But now we have to declare the dependencies twice. It is not pleasant, especially in CoffeeScript. These should explain why Angular code can be broken by minifying code during the steps of mangling variable names / parameter names. ng-annotate (linked above) is a pre-minifier which takes a JavaScript source code, and adds the appropriate annotation to the function, making the resulting code safe-to-minify. I hope this answers your question. I really like Harp, especially when I want to do rapid prototyping. This is where Harp's convention-over-configuration shines brightly. |
Yep, Angular exposes some APIs that can be problematic with magnification. @dtinth thanks for breaking it down. I think we need to give a magnification flag strong consideration almost due to this issue alone. |
Angularjs didn't not return Errors "nicely". This error is because I forget remove a unused provider. (wrote in coffee) |
After upgrading Harp, my AngularJS code stops working, because minification.
Possible solutions:
The text was updated successfully, but these errors were encountered: