AngularJS not working when opimization is enabled ASP.NET MVC
For me the problem was that my selec2.js
and select2.min.js
files were different, enabling optimization or disabling debug caused ASP.NET to use select2.min.js
which in fact was incompatible with my framework and caused it to become invisible and throw error.
updating select2.min.js
solved my problem.
This is a very common problem that happens when using inline annotation for injecting the dependencies, rather than using an Array of strings.
So if you are doing this:
.controller('dummyController', function($scope){...})
You should be doing this:
.controller('dummyController', ['$scope', function($scope){...}])
For example: in your code you are doing this, which won't work well when the code gets minified:
angular.module('allyhrms').service('LocationService', function ($http) {
this.States = function () {
return GetData($http, "/Location/States", {});
};
this.Cities = function (model) {
return PostData($http, "/Location/Cities", { s: model });
}
});
You should be doing it like this instead:
angular.module('allyhrms').service('LocationService',['$http', function ($http) {
this.States = function () {
return GetData($http, "/Location/States", {});
};
this.Cities = function (model) {
return PostData($http, "/Location/Cities", { s: model });
}
}]);