var saveItem = function saveItem (primaryKey, itemName) {
// saves already drafted and tag-filled item
var deferred = $q.defer();
$http.put(Env.domainName + '/item/' + primaryKey + '/', {
pk: primaryKey,
name: itemName,
is_draft: false
})
.success(function (data) {
deferred.resolve(data);
return data;
})
.error(function (data) {
console.error('ItemFactory saveItem error', data);
deferred.reject(true);
})
return deferred.promise;
}
Przykład z AngularJSBestPractices
angular.module( '[your module name]',
... [some dependencies] ...
'ngCookies',
... [other dependencies] ...
)
(...)
.run( function run( titleService, $http, $cookies ){
// For CSRF token compatibility with Django
$http.defaults.headers.post['X-CSRFToken'] = $cookies['csrftoken'];
})