문제

I got a problem with angularJS , I got two factories and when I want to call a methode of one factory in the other I get this error : TypeError: Cannot call method 'getValue' of undefined

my two factories :

technoServices.factory('Shared',
    function(){
        var Shared={};
        Shared.setValue=function(header){
                Shared.header = header;
            }
        Shared.getValue=function(){

                return Shared.header;
            }
        return Shared;
        });

technoServices.factory('Config',['$resource','Shared',
  function($rootScope,$resource,token,Shared){

return $resource('../../rest/config',null,{
    get: {
        method:'GET',
        headers:{'X-Token':''+Shared.getValue()},
        isArray:false}
});
}]);

The error is when i do : Shared.getValue()

도움이 되었습니까?

해결책

In your Config factory definition injection array is not matching the parameters of the function. You declared two elements whereas your function signature expects four arguments so the last two are going to be undefined.

technoServices.factory('Config',['$resource','Shared',
  function($rootScope,$resource,token,Shared){

Something like:

technoServices.factory('Config',['$rootScope', '$resource', 'token', 'Shared',
  function($rootScope,$resource,token,Shared){
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top