From 49660c69043b025ff40a921f7db2749eaa2e2f87 Mon Sep 17 00:00:00 2001 From: Sekib Omazic Date: Fri, 28 Feb 2014 12:39:10 +0100 Subject: [PATCH 1/5] fix(style): expressions in style tags Enable data-binding for style tags closes #2387 --- src/ng/directive/style.js | 2 +- test/ng/directive/styleSpec.js | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/ng/directive/style.js b/src/ng/directive/style.js index 68ea1465f109..1e700aab3ddd 100644 --- a/src/ng/directive/style.js +++ b/src/ng/directive/style.js @@ -2,5 +2,5 @@ var styleDirective = valueFn({ restrict: 'E', - terminal: true + terminal: false }); diff --git a/test/ng/directive/styleSpec.js b/test/ng/directive/styleSpec.js index bdc4ea858bf8..897e6cc16c10 100644 --- a/test/ng/directive/styleSpec.js +++ b/test/ng/directive/styleSpec.js @@ -9,13 +9,20 @@ describe('style', function() { }); - it('should not compile style element', inject(function($compile, $rootScope) { - element = jqLite(''); + it('should compile style element', inject(function($compile, $rootScope) { + element = jqLite(''); $compile(element)($rootScope); $rootScope.$digest(); // read innerHTML and trim to pass on IE8 - expect(trim(element[0].innerHTML)).toBe('should {{notBound}}'); + expect(trim(element[0].innerHTML)).toBe('.some-container{ width: px; }'); + + $rootScope.$apply(function() { + $rootScope.elementWidth = 200; + }); + + // read innerHTML and trim to pass on IE8 + expect(trim(element[0].innerHTML)).toBe('.some-container{ width: 200px; }'); })); From 3b881a4a8f658e9cd1a212b11db5c21b84568bbb Mon Sep 17 00:00:00 2001 From: Sekib Omazic Date: Fri, 28 Feb 2014 13:54:17 +0100 Subject: [PATCH 2/5] test changed to show that binding works for complex expressions --- test/ng/directive/styleSpec.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/test/ng/directive/styleSpec.js b/test/ng/directive/styleSpec.js index 897e6cc16c10..fc6bc7899b16 100644 --- a/test/ng/directive/styleSpec.js +++ b/test/ng/directive/styleSpec.js @@ -10,19 +10,30 @@ describe('style', function() { it('should compile style element', inject(function($compile, $rootScope) { - element = jqLite(''); + element = jqLite(''); $compile(element)($rootScope); $rootScope.$digest(); // read innerHTML and trim to pass on IE8 - expect(trim(element[0].innerHTML)).toBe('.some-container{ width: px; }'); + expect(trim(element[0].innerHTML)).toBe( + '.navigation{font-size:1.5em; h3{font-size:1.5em}}' + + '.footer{h3{font-size:em}}' + + '.header{font-size:1.5em; h3{font-size:}}'); $rootScope.$apply(function() { - $rootScope.elementWidth = 200; + $rootScope.fontSize = 1.5; + $rootScope.unit = 'em'; }); // read innerHTML and trim to pass on IE8 - expect(trim(element[0].innerHTML)).toBe('.some-container{ width: 200px; }'); + expect(trim(element[0].innerHTML)).toBe( + '.navigation{font-size:1.5em; h3{font-size:1.5em}}' + + '.footer{h3{font-size:1.5em}}' + + '.header{font-size:1.5em; h3{font-size:1.5em}}'); })); From 423d9dc0944820ccd3720a8d180c6d737f5efbf1 Mon Sep 17 00:00:00 2001 From: Sekib Omazic Date: Fri, 28 Feb 2014 20:48:20 +0100 Subject: [PATCH 3/5] remove illegal trailing whitespace --- test/ng/directive/styleSpec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/ng/directive/styleSpec.js b/test/ng/directive/styleSpec.js index fc6bc7899b16..36c1891ad823 100644 --- a/test/ng/directive/styleSpec.js +++ b/test/ng/directive/styleSpec.js @@ -21,7 +21,7 @@ describe('style', function() { // read innerHTML and trim to pass on IE8 expect(trim(element[0].innerHTML)).toBe( '.navigation{font-size:1.5em; h3{font-size:1.5em}}' + - '.footer{h3{font-size:em}}' + + '.footer{h3{font-size:em}}' + '.header{font-size:1.5em; h3{font-size:}}'); $rootScope.$apply(function() { From d24fbb92ab332b482f3de7d51a4de054631e2ded Mon Sep 17 00:00:00 2001 From: Sekib Omazic Date: Sat, 1 Mar 2014 11:44:35 +0100 Subject: [PATCH 4/5] make tests more readable --- test/ng/directive/styleSpec.js | 44 ++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/test/ng/directive/styleSpec.js b/test/ng/directive/styleSpec.js index 36c1891ad823..b15bb78c9e74 100644 --- a/test/ng/directive/styleSpec.js +++ b/test/ng/directive/styleSpec.js @@ -9,33 +9,47 @@ describe('style', function() { }); - it('should compile style element', inject(function($compile, $rootScope) { - element = jqLite(''); + it('should compile style element without binding', inject(function($compile, $rootScope) { + element = jqLite(''); $compile(element)($rootScope); $rootScope.$digest(); // read innerHTML and trim to pass on IE8 - expect(trim(element[0].innerHTML)).toBe( - '.navigation{font-size:1.5em; h3{font-size:1.5em}}' + - '.footer{h3{font-size:em}}' + - '.header{font-size:1.5em; h3{font-size:}}'); + expect(trim(element[0].innerHTML)).toBe('.header{font-size:1.5em; h3{font-size:1.5em}}'); + })); + + it('should compile style element with one bind', inject(function($compile, $rootScope) { + element = jqLite(''); + $compile(element)($rootScope); + $rootScope.$digest(); + + // read innerHTML and trim to pass on IE8 + expect(trim(element[0].innerHTML)).toBe('.header{h3{font-size:em}}'); $rootScope.$apply(function() { $rootScope.fontSize = 1.5; - $rootScope.unit = 'em'; }); // read innerHTML and trim to pass on IE8 - expect(trim(element[0].innerHTML)).toBe( - '.navigation{font-size:1.5em; h3{font-size:1.5em}}' + - '.footer{h3{font-size:1.5em}}' + - '.header{font-size:1.5em; h3{font-size:1.5em}}'); + expect(trim(element[0].innerHTML)).toBe('.header{h3{font-size:1.5em}}'); })); + it('should compile style element with two binds', inject(function($compile, $rootScope) { + element = jqLite(''); + $compile(element)($rootScope); + $rootScope.$digest(); + + // read innerHTML and trim to pass on IE8 + expect(trim(element[0].innerHTML)).toBe('.header{h3{font-size:}}'); + + $rootScope.$apply(function() { + $rootScope.fontSize = 1.5; + $rootScope.unit = 'em'; + }); + + // read innerHTML and trim to pass on IE8 + expect(trim(element[0].innerHTML)).toBe('.header{h3{font-size:1.5em}}'); + })); it('should compile content of element with style attr', inject(function($compile, $rootScope) { element = jqLite('
{{bind}}
'); From a2446ac808adb3d7fb7e495c052289e83bdc081a Mon Sep 17 00:00:00 2001 From: Sekib Omazic Date: Sat, 1 Mar 2014 12:36:09 +0100 Subject: [PATCH 5/5] add one more test with simple bind --- test/ng/directive/styleSpec.js | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/test/ng/directive/styleSpec.js b/test/ng/directive/styleSpec.js index b15bb78c9e74..665819fcf419 100644 --- a/test/ng/directive/styleSpec.js +++ b/test/ng/directive/styleSpec.js @@ -18,29 +18,45 @@ describe('style', function() { expect(trim(element[0].innerHTML)).toBe('.header{font-size:1.5em; h3{font-size:1.5em}}'); })); + it('should compile style element with one simple bind', inject(function($compile, $rootScope) { + element = jqLite(''); + $compile(element)($rootScope); + $rootScope.$digest(); + + // read innerHTML and trim to pass on IE8 + expect(trim(element[0].innerHTML)).toBe('.some-container{ width: px; }'); + + $rootScope.$apply(function() { + $rootScope.elementWidth = 200; + }); + + // read innerHTML and trim to pass on IE8 + expect(trim(element[0].innerHTML)).toBe('.some-container{ width: 200px; }'); + })); + it('should compile style element with one bind', inject(function($compile, $rootScope) { - element = jqLite(''); + element = jqLite(''); $compile(element)($rootScope); $rootScope.$digest(); // read innerHTML and trim to pass on IE8 - expect(trim(element[0].innerHTML)).toBe('.header{h3{font-size:em}}'); + expect(trim(element[0].innerHTML)).toBe('.header{ h3 { font-size: em }}'); $rootScope.$apply(function() { $rootScope.fontSize = 1.5; }); // read innerHTML and trim to pass on IE8 - expect(trim(element[0].innerHTML)).toBe('.header{h3{font-size:1.5em}}'); + expect(trim(element[0].innerHTML)).toBe('.header{ h3 { font-size: 1.5em }}'); })); it('should compile style element with two binds', inject(function($compile, $rootScope) { - element = jqLite(''); + element = jqLite(''); $compile(element)($rootScope); $rootScope.$digest(); // read innerHTML and trim to pass on IE8 - expect(trim(element[0].innerHTML)).toBe('.header{h3{font-size:}}'); + expect(trim(element[0].innerHTML)).toBe('.header{ h3 { font-size: }}'); $rootScope.$apply(function() { $rootScope.fontSize = 1.5; @@ -48,7 +64,7 @@ describe('style', function() { }); // read innerHTML and trim to pass on IE8 - expect(trim(element[0].innerHTML)).toBe('.header{h3{font-size:1.5em}}'); + expect(trim(element[0].innerHTML)).toBe('.header{ h3 { font-size: 1.5em }}'); })); it('should compile content of element with style attr', inject(function($compile, $rootScope) {