Skip to content

Commit ade12ec

Browse files
committed
fix(uiGridStyle): <br>s were being needlessly added
1 parent 5687723 commit ade12ec

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/js/directives/ui-grid-style.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@
3030

3131
var app = angular.module('ui.grid.style', []);
3232

33-
app.directive('uiGridStyle', ['$interpolate', function($interpolate) {
33+
app.directive('uiGridStyle', ['$interpolate', '$sce', function($interpolate, $sce) {
3434
return {
3535
// restrict: 'A',
3636
priority: 1000,
3737
link: function(scope, element) {
3838
var interpolateFn = $interpolate(element.text(), true);
39+
3940
if (interpolateFn) {
4041
scope.$watch(interpolateFn, function(value) {
41-
element[0].innerText = value;
42+
element.text(value);
4243
});
4344
}
4445
}

test/unit/directives/ui-grid-style.spec.js

+20
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ describe('ui.grid.style', function() {
44

55
beforeEach(module('ui.grid.style'));
66

7+
beforeEach(module(function($sceProvider) {
8+
$sceProvider.enabled(true);
9+
}));
10+
711
describe('ui-grid-style', function() {
812
var element, scope, compile, recompile;
913

@@ -30,6 +34,22 @@ describe('ui.grid.style', function() {
3034
recompile();
3135
expect(element.text()).toEqual('{{ foo }}');
3236
});
37+
38+
it('does not create useless <br>s', function() {
39+
element = angular.element("<style ui-grid-style>{{ foo }}</style>");
40+
scope.foo = '\n.bar { color: red }\n';
41+
recompile();
42+
dump(element.html());
43+
expect(element.html()).toEqual(scope.foo);
44+
});
45+
46+
it('works when mixing text and expressions', function() {
47+
element = angular.element("<style ui-grid-style>.blah { color: {{ color }}; }</style>");
48+
scope.color = 'black';
49+
recompile();
50+
dump(element.html());
51+
expect(element.html()).toEqual('.blah { color: black; }');
52+
});
3353
});
3454

3555
});

0 commit comments

Comments
 (0)