0

私は..としてファクトリメソッドを持っています

(function (angular) {
         "use strict";
          angular
        .module('app')
        .factory('UserService', ['$rootScope', '$q', function ($rootScope, $q) {
       var markCurrentUserAsContentOwner = function () {
                    var user = getCurrentUser(true);
                    user.set('isContentOwner',"true");
                    user.save(null, {
                    success: function(savedUser) {
                       alert("succes"); 
                     },
                    error: function(savedUser,error) {
                         alert("error");
                    }
                });   

        };
 }]);

})(angular);

今、別のサービスメソッドからこのメソッドを呼び出すと..

(function(angular) {
'use strict';

angular
    .module('app')
    .service('ContentOwnerService',
    [
        '$q', 'UserService'
        function($q, userService) {
var servicemethod=function() {
userService.markCurrentUserAsContentOwner();//UserService is the factory name 
};
}]);

})(angular);

エラーが表示されます..Uncaught TypeError: undefined is not a function. 誰でもこのエラーを解決するのを手伝ってください..

4

1 に答える 1

2

$injectorこの問題を解決するには、サービスを 使用してください。

session.factory('redirectInterceptor', ['$injector','$rootScope', '$timeout', '$q', '$window', function($injector,$rootScope, $timeout, $q, $window) {
return {
    'request': function(req) {

        req.headers['CustomHeader'] = "Be Creative!";
        return req || $q.when(req);

    },
    'response': function(response) {
        if (response.data.Status === 'Failed...') {

            var AuthenticationService = $injector.get('AuthenticationService'); 
            AuthenticationService.ClearCredentials();

            $window.location.href = "/#/login";
            $timeout(function() {
                $rootScope.sessiondata = true;
            }, 5000)

            return $q.reject(response);
        } else {
            return response;
        }
     }
}}])
于 2016-04-30T10:16:31.437 に答える