A Pen by Marcos Sandrini on CodePen.
Created
January 30, 2015 13:38
-
-
Save msandrini/55db011967bc3840de13 to your computer and use it in GitHub Desktop.
Angular pseudo-check directive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div ng-app="demo"> | |
<div ng-controller="demoCtrl"> | |
<a pseudo-check data-model="myVar">Check</a> | |
</div> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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