javascript - Making a Session service available to my SessionsController in AngularJS -
this matter of me not handling dependency injection proper, i'm trying make 'session' service available sessionscontroller. here's sessionscontroller:
angular.module('app.controllers').controller('sessionscontroller', ['$scope', '$location', '$cookiestore', 'session', function($scope, $location, $cookiestore, session) { $scope.foo = function() { console.log("clicked foo.."); } $scope.session = session.usersession; $scope.create = function() { if ( session.signedout ) { $scope.session.$save() .success(function(data, status, headers, config) { $cookiestore.put('_app_user', data); }); } }; $scope.destroy = function() { $scope.session.$destroy(); }; }]);
here's actual session service definition:
angular.module('app.services').service('session',[ '$cookiestore', 'usersession', 'userregistration', function($cookiestore, usersession, userregistration) { this.currentuser = $cookiestore.get('_app_user'); this.signedin = !!$cookiestore.get('_app_user'); this.signedout = !this.signedin; this.usersession = new usersession( { email:"foo@bar.com", password:"example", remember_me:true } ); //this.userregistration = new userregistration( { email:"foo-" + math.floor((math.random()*10000)+1) + "@bar.com", password:"example", password_confirmation:"example" } ); $rootscope.$on('$routechangestart', function (current, next) { if (this.signedout && next !== '/login') { console.log("relocating user.."); //$location('/login'); }}); }]);
and here's how strung together:
angular.module('app.resources', ['ngresource']); angular.module('app.services', ['ngresource']); angular.module('app.directives', []); angular.module('app.filters', []); angular.module('app.controllers', ['ngcookies', 'session']); var app = angular.module("app", ['app.resources', 'app.services', 'app.directives', 'app.filters', 'app.controllers', 'ui.compat', '$strap.directives', 'templates']);
clearly missing string firebug complaining there no module named: session.
firebug right, have no module named session. have service named session in app.services module.
just remove session module injection, , go.
angular.module('app.controllers', ['ngcookies']);
Comments
Post a Comment