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

Commit

Permalink
fix(style): expressions in style tags
Browse files Browse the repository at this point in the history
Enable data-binding for style tags.

Note: this feature does not work on IE8.

Closes #2387
Closes #6492
  • Loading branch information
SekibOmazic authored and IgorMinar committed Mar 6, 2014
1 parent 7682e57 commit 0609453
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/ng/directive/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

var styleDirective = valueFn({
restrict: 'E',
terminal: true
terminal: false
});
58 changes: 55 additions & 3 deletions test/ng/directive/styleSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,65 @@ describe('style', function() {
});


it('should not compile style element', inject(function($compile, $rootScope) {
element = jqLite('<style type="text/css">should {{notBound}}</style>');
it('should compile style element without binding', inject(function($compile, $rootScope) {
element = jqLite('<style type="text/css">.header{font-size:1.5em; h3{font-size:1.5em}}</style>');
$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('.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('<style type="text/css">.some-container{ width: {{elementWidth}}px; }</style>');
$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('<style type="text/css">.header{ h3 { font-size: {{fontSize}}em }}</style>');
$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;
});

// read innerHTML and trim to pass on IE8
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('<style type="text/css">.header{ h3 { font-size: {{fontSize}}{{unit}} }}</style>');
$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 }}');
}));


Expand Down

0 comments on commit 0609453

Please sign in to comment.