I'm trying to play with angularjs and restangular. I have problems using restangular as it give me an error:
TypeError: undefined is not a function
at Object.login (localhost:8000/src/common/factories/session.js:110:38)
at localhost:8000/src/common/factories/session.js:207:34
at Scope.$emit (localhost:8000/vendor/angular/angular.js:12809:33)
at Scope.$scope.Login (localhost:8000/src/common/factories/session.js:185:28)
at localhost8000/vendor/angular/angular.js:10735:21
at localhost:8000/vendor/angular/angular.js:18942:17
at Scope.$eval (localhost:8000/vendor/angular/angular.js:12595:28)
at Scope.$apply (localhost:8000/vendor/angular/angular.js:12693:23)
at Scope.$delegate.__proto__.$apply (<anonymous>:855:30)
at HTMLButtonElement.<anonymous>
(localhost:8000/vendor/angular/angular.js:18941:21)
My controller is here : https://github.com/Seraf/LISA-WEB-Frontend/blob/master/src/common/factories/session.js#L188 and calling the login function (line and pos in the error above)
Here, it seems it doesn't play well with Restangular as I have the error pasted above. As I'm new to angularjs, maybe I don't do the best practices ... I already inject restangular as dependency on my root module : https://github.com/Seraf/LISA-WEB-Frontend/blob/master/src/app/app.js#L6 maybe it causes some problems ?
[EDIT] Guilty lines are :
110: ".setBaseUrl('backend/api/v1')"
207: "$Session.login(data);"
The guilty code :
angular.module("SessionManager", ['http-auth-interceptor','restangular'])
.constant('constSessionExpiry', 20) // in minutes
.factory("$Session", [
'$rootScope',
'$q',
'$location',
'$log',
'$http',
'constSessionExpiry',
function($rootScope, $q, $location, $log, $http, Restangular, authService, constSessionExpiry) {
return {
login: function(data){
$log.info("Preparing Login Data", data);
var $this = this;
return Restangular
.setBaseUrl('backend/api/v1')
.all('user/login/')
.post(data)
.then(function userLoginSuccess(response){
$log.info("login.post: auth-success", response);
$this.User = response;
// remove properties we don't need.
delete $this.User.route;
delete $this.User.restangularCollection;
$this.User.is_authenticated = true;
$this.cacheUser();
$this.setApiKeyAuthHeader();
$this.authSuccess();
}, function userLoginFailed(response){
$log.info('login.post: auth-failed', response);
$this.logout();
return $q.reject(response);
});
},
};
}])
Thanks for the help !
$Sessionis undefined at L221, at this point I can't be much help since I've never used the angular library, but it looks like whenfunction($rootScope, $log, $Session, $state){is called, that it is not receiving a $Session parameter. L208