1👍
The Task factory is on the myServices
module; but it should be on myApp
. Assuming there are no other errors, this should get around the TaskProvider
not recognized problem…
var my_app = angular.module('myApp', [/* other dependencies */,
'ngResource','ngCookies']).run(function($http, $cookies) {
$http.defaults.headers.post['X-CSRFToken'] = $cookies.csrftoken;
//Add the following two lines
$http.defaults.xsrfCookieName = 'csrftoken';
$http.defaults.xsrfHeaderName = 'X-CSRFToken';
});
my_app.factory('Task', ['$resource', function ($resource) {
return $resource('crud/task', {'pk': '@pk'},{})
}]);
my_app.controller('myCtrl', ['$scope','Task', function ($scope, Task) {
//Query returns an array of objects, Task.objects.all() by default
$scope.models = Task.query();
}]);
myServices
isn’t needed here (just make sure you add the ngResource
dependency to myApp
).
Source:stackexchange.com