Skip to content

Instantly share code, notes, and snippets.

@msandrini
Created January 30, 2015 13:38
Show Gist options
  • Save msandrini/55db011967bc3840de13 to your computer and use it in GitHub Desktop.
Save msandrini/55db011967bc3840de13 to your computer and use it in GitHub Desktop.
Angular pseudo-check directive
<div ng-app="demo">
<div ng-controller="demoCtrl">
<a pseudo-check data-model="myVar">Check</a>
</div>
</div>
var a = angular.module('demo',[]);
a.controller('demoCtrl', function($scope){ });
a.directive('pseudoCheck',function(){
return {
restrict: 'A',
scope: {model:'='},
template: '<a class="pseudocheck" href="javascript:;" ng-class="{active:model}" ng-click="Toggle()">'+
'<span ng-transclude></span></a>',
replace: true,
transclude: true,
link: function($scope, $element){
$scope.Toggle = function(){
$scope.model = !$scope.model;
}
}
}
});
.pseudocheck{
padding:5px;
background:#ccc;
cursor:pointer;
text-decoration:none;
color:#555;
}
.pseudocheck:before{
content:'✘';
display:inline-block;
width:18px;
color:#999;
}
.pseudocheck.active:before{
content:'✔';
color:#F70;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment