I'm encountering an error message saying "Base64.encode is not a function," but I'm unsure why:
The 'login-controller' controller below utilizes the LoginService:
angular.module('app')
.controller('login-controller',
['$scope', '$location', '$http', 'LoginService',
function($scope, $location, $http, LoginService) {
...
if(LoginService.login($scope.user.name, $scope.user.password) == true)
{
$location.path('/chooseMandantAsk')
}
else
{
$scope.wrongCredentials = true;
}
...
}]);
The following LoginService makes use of a function from the Base64 Service:
angular.module('app')
.service('LoginService', ['$location', '$http', 'Base64', function ($http, Base64) {
...
this.login = function (name, password){
user.auth= "Basic " + Base64.encode(name + ":" + password);
$http.defaults.headers.common.Authorization = user.auth;
$http.get(url+'/login')
.success(function(){
return true;
})
.error(function(){
user.auth = "";
delete $http.defaults.headers.common['Authorization'];
return false;
});
};
...
}]);
The Base64 service includes a method called encode:
angular.module('app').factory('Base64', function () {
var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
return {
encode: function (input) {
...
return output;
},
decode: function (input) {
...
return output;
}
};
});
I have previously used the Base64.encode method in a different manner and it worked fine.
If anyone could assist me in understanding this error, I would greatly appreciate it.
Best regards,
Matthias