angularjs - Can't access service in controller -
so i'm trying retrieve token server i'm encountering error when trying call method in service.
logincontroller.js:
(function(){ angular.module('app') .controller('logincontroller', [ '$http', 'authservice', logincontroller ]); function logincontroller(authservice ) { var vm = this; vm.user = {}; vm.login = function () { console.log("logging in"); authservice.gettoken("admin", "admin") .then(function (data) { console.log(data); }, function (error) { //todo: error handling }) }; } })();
authservice.js:
(function(){ 'use strict'; angular .module('app') .factory('authservice', ['$http', '$rootscope', 'rest_end_point', authservice ]); function authservice($http, $rootscope, rest_end_point){ return { gettoken: function(username, password) { var config = { headers: { 'accept': 'application/json' } }; var data = { username: login, password: password }; return $http.post(rest_end_point, +"/authenticate", data, config); } }; } })();
i keep getting error :
typeerror: authservice.gettoken not function @ logincontroller.vm.login
you forgot add $http controller function.
angular.module('app') .controller('logincontroller', [ '$http', 'authservice', logincontroller ]); function logincontroller(_$http_needs_to_be_here, authservice ) { ...
Comments
Post a Comment