简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM