From ccd6076904a4b801d77b47f6e2de4c06ce9962f8 Mon Sep 17 00:00:00 2001 From: Jim OBrien Date: Fri, 5 Sep 2014 21:01:05 -0700 Subject: [PATCH] feat($templateFactory): request templateURL as text/html Add "Accept: text/html" to headers of $http.get invocation Closes issue #1287 --- src/templateFactory.js | 2 +- test/templateFactorySpec.js | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/templateFactory.js b/src/templateFactory.js index ebb86d353..ca491a987 100644 --- a/src/templateFactory.js +++ b/src/templateFactory.js @@ -83,7 +83,7 @@ function $TemplateFactory( $http, $templateCache, $injector) { if (isFunction(url)) url = url(params); if (url == null) return null; else return $http - .get(url, { cache: $templateCache }) + .get(url, { cache: $templateCache, headers: { Accept: 'text/html' }}) .then(function(response) { return response.data; }); }; diff --git a/test/templateFactorySpec.js b/test/templateFactorySpec.js index f330dadc2..ff72dd303 100644 --- a/test/templateFactorySpec.js +++ b/test/templateFactorySpec.js @@ -1,8 +1,16 @@ describe('templateFactory', function () { - + beforeEach(module('ui.router.util')); it('exists', inject(function ($templateFactory) { expect($templateFactory).toBeDefined(); })); + + it('should request templates as text/html', inject(function($templateFactory, $httpBackend) { + $httpBackend.expectGET('views/view.html', function(headers) { + return headers.Accept === 'text/html'; + }).respond(200); + $templateFactory.fromUrl('views/view.html'); + $httpBackend.flush(); + })); });