BT101 BT101 - 2 years ago 71
AngularJS Question

How to protect angularJS controller from minify

So I know that I need to use

to secure my code before minification. For example:

app.controller('mainController', ['$scope', function($scope) {
$scope.message = 'HOORAY!';

But how to do that when I am not using
as global variable, I've got

(function () {
'use strict';

.controller('loginCtrl', Controller);

function Controller($scope, authService) {
var vm = $scope;
vm.login = function(login_field, password_field) {
var loginData = {
login: login_field,
password: password_field

How to prevent it from problems during minification?

Answer Source

The same way:

.controller('loginCtrl', ['$scope', 'authService', Controller]);

I strongly advise you to use ng-annotate, which allows using the simple syntax, and transforms it into minifiable code for you. That will make your code simpler, easier to read, and avoid a whole lot of bugs.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download