Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 0609453

Browse files
SekibOmazicIgorMinar
authored andcommitted
fix(style): expressions in style tags
Enable data-binding for style tags. Note: this feature does not work on IE8. Closes #2387 Closes #6492
1 parent 7682e57 commit 0609453

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed

src/ng/directive/style.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
var styleDirective = valueFn({
44
restrict: 'E',
5-
terminal: true
5+
terminal: false
66
});

test/ng/directive/styleSpec.js

+55-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,65 @@ describe('style', function() {
99
});
1010

1111

12-
it('should not compile style element', inject(function($compile, $rootScope) {
13-
element = jqLite('<style type="text/css">should {{notBound}}</style>');
12+
it('should compile style element without binding', inject(function($compile, $rootScope) {
13+
element = jqLite('<style type="text/css">.header{font-size:1.5em; h3{font-size:1.5em}}</style>');
1414
$compile(element)($rootScope);
1515
$rootScope.$digest();
1616

1717
// read innerHTML and trim to pass on IE8
18-
expect(trim(element[0].innerHTML)).toBe('should {{notBound}}');
18+
expect(trim(element[0].innerHTML)).toBe('.header{font-size:1.5em; h3{font-size:1.5em}}');
19+
}));
20+
21+
22+
it('should compile style element with one simple bind', inject(function($compile, $rootScope) {
23+
element = jqLite('<style type="text/css">.some-container{ width: {{elementWidth}}px; }</style>');
24+
$compile(element)($rootScope);
25+
$rootScope.$digest();
26+
27+
// read innerHTML and trim to pass on IE8
28+
expect(trim(element[0].innerHTML)).toBe('.some-container{ width: px; }');
29+
30+
$rootScope.$apply(function() {
31+
$rootScope.elementWidth = 200;
32+
});
33+
34+
// read innerHTML and trim to pass on IE8
35+
expect(trim(element[0].innerHTML)).toBe('.some-container{ width: 200px; }');
36+
}));
37+
38+
39+
it('should compile style element with one bind', inject(function($compile, $rootScope) {
40+
element = jqLite('<style type="text/css">.header{ h3 { font-size: {{fontSize}}em }}</style>');
41+
$compile(element)($rootScope);
42+
$rootScope.$digest();
43+
44+
// read innerHTML and trim to pass on IE8
45+
expect(trim(element[0].innerHTML)).toBe('.header{ h3 { font-size: em }}');
46+
47+
$rootScope.$apply(function() {
48+
$rootScope.fontSize = 1.5;
49+
});
50+
51+
// read innerHTML and trim to pass on IE8
52+
expect(trim(element[0].innerHTML)).toBe('.header{ h3 { font-size: 1.5em }}');
53+
}));
54+
55+
56+
it('should compile style element with two binds', inject(function($compile, $rootScope) {
57+
element = jqLite('<style type="text/css">.header{ h3 { font-size: {{fontSize}}{{unit}} }}</style>');
58+
$compile(element)($rootScope);
59+
$rootScope.$digest();
60+
61+
// read innerHTML and trim to pass on IE8
62+
expect(trim(element[0].innerHTML)).toBe('.header{ h3 { font-size: }}');
63+
64+
$rootScope.$apply(function() {
65+
$rootScope.fontSize = 1.5;
66+
$rootScope.unit = 'em';
67+
});
68+
69+
// read innerHTML and trim to pass on IE8
70+
expect(trim(element[0].innerHTML)).toBe('.header{ h3 { font-size: 1.5em }}');
1971
}));
2072

2173

0 commit comments

Comments
 (0)