From db17a735aa2f556265be68baa529881d2008c8db Mon Sep 17 00:00:00 2001 From: Andrew Shcheglov Date: Fri, 17 Aug 2012 22:57:34 +0300 Subject: [PATCH] fix($http): replace delete() with del() In some browsers, like IE8 and android ones, calling delete as a method causes parse error Closes #1265 --- src/ng/http.js | 28 ++++++++++++++++++---------- test/ng/httpSpec.js | 8 ++++---- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/ng/http.js b/src/ng/http.js index ef55f8787bf4..7b7f027be141 100644 --- a/src/ng/http.js +++ b/src/ng/http.js @@ -544,11 +544,11 @@ function $HttpProvider() { /** * @ngdoc method - * @name ng.$http#delete + * @name ng.$http#head * @methodOf ng.$http * * @description - * Shortcut method to perform `DELETE` request + * Shortcut method to perform `HEAD` request * * @param {string} url Relative or absolute URL specifying the destination of the request * @param {Object=} config Optional configuration object @@ -557,31 +557,39 @@ function $HttpProvider() { /** * @ngdoc method - * @name ng.$http#head + * @name ng.$http#jsonp * @methodOf ng.$http * * @description - * Shortcut method to perform `HEAD` request + * Shortcut method to perform `JSONP` request * - * @param {string} url Relative or absolute URL specifying the destination of the request + * @param {string} url Relative or absolute URL specifying the destination of the request. + * Should contain `JSON_CALLBACK` string. * @param {Object=} config Optional configuration object * @returns {HttpPromise} Future object */ + createShortMethods('get', 'head', 'jsonp'); + /** * @ngdoc method - * @name ng.$http#jsonp + * @name ng.$http#del * @methodOf ng.$http * * @description - * Shortcut method to perform `JSONP` request + * Shortcut method to perform `DELETE` request * - * @param {string} url Relative or absolute URL specifying the destination of the request. - * Should contain `JSON_CALLBACK` string. + * @param {string} url Relative or absolute URL specifying the destination of the request * @param {Object=} config Optional configuration object * @returns {HttpPromise} Future object */ - createShortMethods('get', 'delete', 'head', 'jsonp'); + $http.del = function(url, config) { + return $http(extend(config || {}, { + method: 'DELETE', + url: url + })); + } + /** * @ngdoc method diff --git a/test/ng/httpSpec.js b/test/ng/httpSpec.js index f7df3d4b06c3..78cecb8219c1 100644 --- a/test/ng/httpSpec.js +++ b/test/ng/httpSpec.js @@ -483,15 +483,15 @@ describe('$http', function() { }); - it('should have delete()', function() { + it('should have del()', function() { $httpBackend.expect('DELETE', '/url').respond(''); - $http['delete']('/url'); + $http['del']('/url'); }); - it('delete() should allow config param', function() { + it('del() should allow config param', function() { $httpBackend.expect('DELETE', '/url', undefined, checkHeader('Custom', 'Header')).respond(''); - $http['delete']('/url', {headers: {'Custom': 'Header'}}); + $http['del']('/url', {headers: {'Custom': 'Header'}}); });