0

I have declared a factory with three functions in it. I was able to call get function but not the other two.

 todomvc.factory('todoStorage', function ($q,$http) {
        var STORAGE_ID = 'todos-angularjs-perf';
     function get(){
       return $http.get('test.json');
     }
    function display(){
        console.log("testing");
    }
     function put(todos) {
        console.log(todos);
       return $http.get('test.json');
     }
     return{get:get};
     return{put:put};
    });

Calling the functions in controller,

display(); // undefined here
todoStorage.put(todos); // undefined here too

Where I am doing a mistake?

1

1 Answer 1

2

A factory in angular is a function that returns an object.

You have multiple return statements:

return {get: get};
return {pug: put};

Change them to:

return {
  get: get,
  put: put,
  display: display
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.