Agent Zebra Agent Zebra - 4 months ago 21
AngularJS Question

Angular js minify errors

When I try to minify the following code it breaks. What's wrong? What's the simplest way to fix this?

(function () {
'use strict';
angular.module('weatherapp.weatherlist')
.controller('WeatherlistController2', function($scope, utcFactory) {
var vm = this;
vm.utc = utcFactory.myUTC();
})

.factory('utcFactory', function() {
var myUTC = function() {
var offset = -new Date().getTimezoneOffset();
var utc = ((offset > 0 ? '+' : '') + offset / 60);
return utc;
}

return {
myUTC: myUTC
}
});
})();

Answer

This is a common problem. Use the array syntax for your controller:

.controller('WeatherlistController2', [ '$scope', 'utcFactory', function($scope, utcFactory) {}])

See here as well: Angularjs minify best practice