From f51d5cd1e3acb888b18c3a8fa208489e674ffd4b Mon Sep 17 00:00:00 2001 From: Anant Anand Gputa Date: Wed, 16 Nov 2016 05:31:17 +0530 Subject: [PATCH 1/5] use $templateRequest from AngularJS - modified `$templateFactory` to use `$templateRequest` provider of AngularJs in case it is avalable - removed the test case which enforces the setting of request header `Accept: text/html` --- src/templateFactory.js | 12 +++++++++--- test/templateFactorySpec.js | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/templateFactory.js b/src/templateFactory.js index ca491a987..39a0fd67e 100644 --- a/src/templateFactory.js +++ b/src/templateFactory.js @@ -82,9 +82,15 @@ function $TemplateFactory( $http, $templateCache, $injector) { this.fromUrl = function (url, params) { if (isFunction(url)) url = url(params); if (url == null) return null; - else return $http - .get(url, { cache: $templateCache, headers: { Accept: 'text/html' }}) - .then(function(response) { return response.data; }); + else { + if($injector.has('$templateRequest')) { + return $injector.get('$templateRequest')(url); + } else { + return $http + .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 ff72dd303..f52fd44b7 100644 --- a/test/templateFactorySpec.js +++ b/test/templateFactorySpec.js @@ -6,7 +6,7 @@ describe('templateFactory', function () { expect($templateFactory).toBeDefined(); })); - it('should request templates as text/html', inject(function($templateFactory, $httpBackend) { + xit('should request templates as text/html', inject(function($templateFactory, $httpBackend) { $httpBackend.expectGET('views/view.html', function(headers) { return headers.Accept === 'text/html'; }).respond(200); From 9431f6db3b9a2d525e16cb5dda66836e423f7aeb Mon Sep 17 00:00:00 2001 From: Anant Anand Gputa Date: Wed, 16 Nov 2016 05:52:23 +0530 Subject: [PATCH 2/5] error fixed - AngularJS 1.0.8 don't have $injector.has --- src/templateFactory.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/templateFactory.js b/src/templateFactory.js index 39a0fd67e..6d23ff758 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 { - if($injector.has('$templateRequest')) { + if($injector.has && $injector.has('$templateRequest')) { return $injector.get('$templateRequest')(url); } else { return $http From 67e4997eadfc1f7f5af8efd7cb676218cc69129e Mon Sep 17 00:00:00 2001 From: Chris Thielen Date: Tue, 29 Nov 2016 18:47:42 -0600 Subject: [PATCH 3/5] fix(ui-sref-active-eq): Compare parameter values using typed parameters --- src/state.js | 11 +++++++++-- test/stateDirectivesSpec.js | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/state.js b/src/state.js index 652d282c4..1f31f8412 100644 --- a/src/state.js +++ b/src/state.js @@ -1262,7 +1262,11 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) { if (!isDefined(state)) { return undefined; } if ($state.$current !== state) { return false; } - return params ? equalForKeys(state.params.$$values(params), $stateParams) : true; + + return !params || objectKeys(params).reduce(function(acc, key) { + var paramDef = state.params[key]; + return acc && !paramDef || paramDef.type.equals($stateParams[key], params[key]); + }, true); }; /** @@ -1338,7 +1342,10 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) { } } - return true; + return objectKeys(params).reduce(function(acc, key) { + var paramDef = state.params[key]; + return acc && !paramDef || paramDef.type.equals($stateParams[key], params[key]); + }, true); }; diff --git a/test/stateDirectivesSpec.js b/test/stateDirectivesSpec.js index 7966f57c5..2daaf8c05 100644 --- a/test/stateDirectivesSpec.js +++ b/test/stateDirectivesSpec.js @@ -566,6 +566,30 @@ describe('uiSrefActive', function() { expect(angular.element(template[0].querySelector('a')).attr('class')).toBe(''); })); + // Test for #3154 + it('should compare ui-sref-active-eq using typed parameters', inject(function($rootScope, $q, $compile, $state) { + el = angular.element('
foo 123
'); + template = $compile(el)($rootScope); + $rootScope.$digest(); + + expect(angular.element(template[0].querySelector('a')).attr('class')).toBe(''); + + $state.transitionTo('arrayparam', {foo: [1,2,3] }); + $q.flush(); + timeoutFlush(); + expect(angular.element(template[0].querySelector('a')).attr('class')).toBe('active'); + + $state.transitionTo('arrayparam', {foo: [1,2,3], bar: 'asdf' }); + $q.flush(); + timeoutFlush(); + expect(angular.element(template[0].querySelector('a')).attr('class')).toBe('active'); + + $state.transitionTo('arrayparam', {foo: [1,2] }); + $q.flush(); + timeoutFlush(); + expect(angular.element(template[0].querySelector('a')).attr('class')).toBe(''); + })); + it('should update in response to ui-sref param expression changes', inject(function($rootScope, $q, $compile, $state) { el = angular.element('
Contacts
'); template = $compile(el)($rootScope); From 8b4b5d7243a8d666c4746cc69af0ce8e8e6515a7 Mon Sep 17 00:00:00 2001 From: Anant Anand Gputa Date: Wed, 16 Nov 2016 05:31:17 +0530 Subject: [PATCH 4/5] use $templateRequest from AngularJS - modified `$templateFactory` to use `$templateRequest` provider of AngularJs in case it is avalable - removed the test case which enforces the setting of request header `Accept: text/html` --- src/templateFactory.js | 12 +++++++++--- test/templateFactorySpec.js | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/templateFactory.js b/src/templateFactory.js index ca491a987..39a0fd67e 100644 --- a/src/templateFactory.js +++ b/src/templateFactory.js @@ -82,9 +82,15 @@ function $TemplateFactory( $http, $templateCache, $injector) { this.fromUrl = function (url, params) { if (isFunction(url)) url = url(params); if (url == null) return null; - else return $http - .get(url, { cache: $templateCache, headers: { Accept: 'text/html' }}) - .then(function(response) { return response.data; }); + else { + if($injector.has('$templateRequest')) { + return $injector.get('$templateRequest')(url); + } else { + return $http + .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 ff72dd303..f52fd44b7 100644 --- a/test/templateFactorySpec.js +++ b/test/templateFactorySpec.js @@ -6,7 +6,7 @@ describe('templateFactory', function () { expect($templateFactory).toBeDefined(); })); - it('should request templates as text/html', inject(function($templateFactory, $httpBackend) { + xit('should request templates as text/html', inject(function($templateFactory, $httpBackend) { $httpBackend.expectGET('views/view.html', function(headers) { return headers.Accept === 'text/html'; }).respond(200); From 2caf84bbbd6f161361b5cd8b38b8892577765225 Mon Sep 17 00:00:00 2001 From: Anant Anand Gputa Date: Wed, 16 Nov 2016 05:52:23 +0530 Subject: [PATCH 5/5] error fixed - AngularJS 1.0.8 don't have $injector.has --- src/templateFactory.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/templateFactory.js b/src/templateFactory.js index 39a0fd67e..6d23ff758 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 { - if($injector.has('$templateRequest')) { + if($injector.has && $injector.has('$templateRequest')) { return $injector.get('$templateRequest')(url); } else { return $http