Вопрос

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