I am trying to style a checkbox with an angular directive and I came up with a simple solution. My idea is to have in HTML an input like this
<input type="checkbox" class="checkbox" ng-model="abc1"/>
and I want to create a directive that practically wraps this input inside a label with the class check and adds a div after the input so I can target that div after the input with + from CSS and design on it the states of the input.
So my directive should transform my HTML from what I should previous into this
<label class="check">
<input type="checkbox" class="checkbox" ng-model="abc1"/>
<div></div>
</label>
now I created this directive
.directive('checkbox', function() {
return {
restrict: 'C',
transclude: true,
template: '<label><ng-transclude></ng-transclude><div></div></label>',
link: function(scope, elem, attrs) {
}
};
})
but it doesn't do the layout I want to achieve, I hope someone can help me showing the way to write the directive in order to transform it into that HTML output.