Alex Nikolsky
Alex Nikolsky

Reputation: 2179

Provider 'Task' must return a value from $get factory method

I have written an angularjs factory as below

var app = angular.module('Todolist', ['ngResource']);

  app.factory('Task', [
    '$resource', function($resource) {
      $resource('users/:user_id/tasks/:id', {
        id: '@id'
      }, {
        update: {
          method: 'PUT'
        }
      });
    }
  ]);

app.controller('TasksCtrl', [
  '$scope', 'Task', function($scope, Task) {
    $scope.tasks = Task.query({
      status: 'incompleted'
    });

   $scope.completed_tasks = Task.query({
     status: 'completed'
    });

 }
]);

But I keep getting the error and have no clue where I've done the mistake.

Error: [$injector:undef] Provider 'Task' must return a value from $get factory method.

So what's wrong with it?

Upvotes: 0

Views: 588

Answers (1)

toskv
toskv

Reputation: 31632

You are creating a factory. They must have a $get method defined on them that creates new instances of whatever it should be creating. Check the documentation for Provider Recipe here : https://docs.angularjs.org/guide/providers

Upvotes: 2

Related Questions