Reputation: 32808
I have this function in AngularJS. Can someone tell me how I can protect it so that it can be minified:
.factory('isEmailAvailable', function (appConstant, $q, $http) {
return function (email) {
var deferred = $q.defer();
var url = appConstant.baseUrl + '/api/user/existsByEmail';
$http({
url: url,
method: "PUT",
data: {
email: email
}
}).then(function () {
// Found the user, therefore not unique.
deferred.reject("User name is taken");
}, function () {
// User not found, therefore unique!
deferred.resolve();
});
return deferred.promise;
}
});
Upvotes: 1
Views: 47
Reputation: 16217
I think what you mean is to protect dependency injection of this function:
function (appConstant, $q, $http) {}
To do that, change it to an array, telling Angular what you are injecting:
['appConstant', '$q', '$http', function (appConstant, $q, $http) {}]
so it would look like this
.factory('isEmailAvailable', ['appConstant', '$q', '$http', function (appConstant, $q, $http) {
// Your code here
}])
If you are using gulp to automate building your app (it's totally worth it), you can use the gulp-ng-annotate module to do this automatically without adding cruft to the original code.
Upvotes: 5