I have an AngularJS directive which specifies replace: true and template: <span style="color: red;"></span>. Whenever I use the directive in my markup, it seems that the contents of the style attribute is repeated in the DOM: <span style="color: red;;color: red;"></span>. Is this a bug in AngularJS, or am I doing something wrong here?
Here is a Plunk that demonstrates the problem: http://plnkr.co/edit/UMhmjGS3XW84d7zctujo
I do not know what causes this, but it won't harm to list a possible solution.
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {$scope.style={color:red};);
app.directive('myDirective', function() {
return {
replace: true,
template: '<span ng-style="style" class="my-test-class">something!</span>'
};
});
See: ngStyle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With