我正在使用使用Microsoft Ajax Minifier來縮小JS的Cassette。此縮小器會重命名變量,包括對Angular具有特殊含義的變量,例如$scope
和$http
。所以Cassette打破了我的Angular代碼!Minification正在破壞我的AngularJs代碼
我該如何防止這種情況發生?
作爲參考,這是正在被破壞的角碼。該$scope
和$http
功能參數被重命名:
// <reference path="vendor/angular.js" />
angular.module('account-module', [])
.controller('ForgottenPasswordController', function ($scope, $http) {
$scope.email = {
value: '',
isValid: false,
containerStyle: "unvalidated",
validate: function() {
var valid = isEmailAdressValid($scope.email.value);
$scope.email.isValid = valid;
$scope.email.containerStyle = valid ? "valid" : "invalid";
return valid;
},
removeErrorMessage: function() {
$scope.email.containerStyle = "unvalidated";
}
};
$scope.display = {
formClass: '',
congratulationsClass: 'hide'
};
$scope.submit = function (event) {
event.preventDefault();
var emailValid = $scope.email.validate();
if (emailValid) {
$http({
method: 'POST',
url: '/account/forgot-password',
params: { email: $scope.email.value },
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).success(function(data) {
$scope.success(data);
}).error(function() { $scope.error(); });
}
};
$scope.success = function (data) {
switch (data.Outcome) {
case 1:
$scope.display.formClass = "hide";
$scope.display.congratulationsClass = "";
break;
case 2:
$scope.email.containerStyle = "invalid";
break;
}
};
$scope.error = function() {
alert('Sorry, an error occurred.');
};
function isEmailAdressValid(emailAddress) {
return /[^\[email protected]][email protected][^\[email protected]]+\.[^\[email protected]]+/.test(emailAddress);
}
});
您能否向我們展示您的控制器語法,然後我們可以評論您使用的是正確的語法還是錯誤的語法 –