Для единственного визуального редактора я пытаюсь создать новую директиву, которая пишет стиль CSS. Я застрял в попытке получить директиву для обновления при нажатии флажка, чтобы сделать свойство background-color прозрачным.
Вот моя (нерабочая) директива:
myApp.directive('customstyle', function () {
return {
restrict: 'E',
link: function (scope, element, attrs) {
var bgColor;
scope.$watch(attrs.myTransparent, function (value) {
if (value) {
bgColor = 'transparent';
} else {
bgColor = attrs.myBgcolor;
}
updateStyle();
}, true);
function updateStyle() {
var htmlText = '<style>.' + attrs.myClass + '{';
htmlText += 'background-color: ' + bgColor + ';';
htmlText += "}</style>";
element.replaceWith(htmlText);
}
updateStyle();
}
}
});
и HTML-элемент:
<customstyle my-class="examplediv" my-transparent="settings.Window.Transparent" my-bgcolor="settings.Window.BackgroundColor"></customstyle>
Вот jsfiddle ситуации: http://jsfiddle.net/psinke/jYQc6/
Любая помощь будет принята с благодарностью.