1

I created custom service

(function () {
    "use strict";

    angular
        .module("common.services")        
        .factory("redirectService",
                ["$q", "$location", 
                 redirectService])
        .config(function ($httpProvider) {
             $httpProvider.interceptors.push('redirectService');
        });

    function redirectService($q, $location){
       ...
       var redirect = function() {
            ...
        };

        return {           
            doRedirect: redirect
        };
     }

inside my other controller where I'm injecting this redirectService I'm trying to call this publish doRedirect method

angular
    .module("myModule")
    .controller("MyController",
                 ["$scope",  
                 "redirectService"                  
                  MyController]);

    function MyController(redirectService){
      vm.doClick = function() {  
        redirectService.doRedirect();
      }
    }

Here I'm getting error on calling doRedirect method

Error: redirectService.doRedirect is not a function

2
  • 1
    Could it be that loginRedirectService should be redirectService on the call
    – Thargor
    Jun 10, 2016 at 11:16
  • you create redirect function but try to return redirectPostLogin. Or you just pasted the code wrongly? Jun 10, 2016 at 11:17

2 Answers 2

2

You have an imbalance of number of arguments in dependency array and function arguments for MyController

Change

function MyController(redirectService){

To

function MyController($scope, redirectService){
0

MyController function has two arguments first $scope, second redirectService

angular
    .module("myModule")
    .controller("MyController",
                 ["$scope",  
                 "redirectService"                  
                  MyController]);

    function MyController($scope, redirectService){
      vm.doClick = function() {  
        redirectService.doRedirect();
      }
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.