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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -