I want to change the color of the icon respect to the button clicked by the user ( say there is a popover which has three buttons namely high,medium , low . if a user clicks "high" it should changes to red color. medium - orange.. low - blue.. I made a directive for popover with three buttons. but i am unable to update the css classes with respect to the button click.
html:
<span class="tk-action-s">
<i priority-over class="fa fa-star {{colorChanger}}" ng-class="colorChanger"></i>
</span>
directive :
myApplication.directive('priorityOver', function ($compile) {
var itemsTemplate = "<div class=\"btn-group\"></div><div class=\"btn-group\"><label class=\"btn btn-danger\" ng-model=\"priority\" btn-radio=\"'high'\" ng-click=\"changeColor()\" uncheckable>High</label><label class=\"btn btn-warning\" ng-model=\"priority\" btn-radio=\"'medium'\" uncheckable>Medium</label><label class=\"btn btn-primary\" ng-model=\"priority\" btn-radio=\"'low'\" uncheckable>Low</label></div>";
var getTemplate = function () {
var template = '';
template = itemsTemplate;
return template;
}
return {
restrict: "AC",
transclude: true,
template: "<span ng-transclude></span>",
controller: function($scope, $element, $attrs) {
$scope.colorChanger = 'col';
},
link: function (scope, element, attrs) {
scope.colorChanger = 'col' ;
var popOverContent;
var html = getTemplate();
popOverContent = $compile(html)(scope);
var options = {
content: popOverContent,
placement: "bottom",
html: true,
//title: scope.title
};
$(element).popover(options);
$('body').on('click', function (e) {
$(element).each(function () {
// hide any open popovers when the anywhere else in the body is clicked
if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) {
$(this).popover('hide');
}
});
});
}
};
});
scope.$watch('$destroy', function(){...}).itemsTemplate? Why are you using both a dynamicclassattribute andng-class? Have you tried adding a CSS class in your link function likeelement.addClass('myclass')(the element is already jQuery, no need to wrap it)?