Angular Office not working after miniature JS file?

I am new to AngularJS. I created a new application in VS2012 using AngularJS. I applied minification to my JavaScript file, but after minification, the binding does not work for me. because the keyword $ scope , which angular understands, is converted to a .

Please let me know how to apply minification to angularJS file?

+4
source share
1 answer

From http://docs.angularjs.org/tutorial/step_05 :

Since angular defines the dependencies of the controller on the argument names of the controller constructor function, if you want to minimize the JavaScript code for the PhoneListCtrl controller, all its function arguments will also be reduced, and the dependency injector will not be able to correctly identify the services.

To overcome the problems caused by minimization, simply assign an array with the service identifier strings to the $ injection property of the controller function, as in the last line in the fragment (commented out):

PhoneListCtrl.$inject = ['$scope', '$http'];

There is also another way to specify this list of dependencies and avoid problems with minimization - using the bracket notation, which wraps the function that needs to be inserted into the string array (representing the dependency names), and then the function that needs to be entered:

var PhoneListCtrl = ['$scope', '$http', function($scope, $http) { /* constructor body */ }];

Both of these methods work with any function that can be introduced using Angular, so before your project style guide you can decide which one you use.

+9
source

Source: https://habr.com/ru/post/1480729/


All Articles