Skip to content

Instantly share code, notes, and snippets.

@msandrini
Created January 30, 2015 13:38
Show Gist options
  • Save msandrini/b3bbd311faf876b44f69 to your computer and use it in GitHub Desktop.
Save msandrini/b3bbd311faf876b44f69 to your computer and use it in GitHub Desktop.
Angular pseudo-radio directive
<div ng-app="demo">
<div ng-controller="demoCtrl">
<div pseudo-radio
data-values="{1:'one', 2:'two', 3:'three'}"
data-model="myVar"></div>
</div>
</div>
var a = angular.module('demo',[]);
a.controller('demoCtrl', function($scope){ });
a.directive('pseudoRadio',function(){
return {
restrict: 'AE',
scope: {values:'=', model:'='},
template: '<a href="javascript:;" class="option" '+
'ng-class="{active:model===v}" '+
'ng-repeat="(v,label) in values" '+
'ng-click="Value(v)">{{label}}</a>',
controller: function($scope, $element){
$scope.Value = function(v){
$scope.model = v;
}
}
}
});
[pseudo-radio]{
background:#999;
padding:3px 0 3px 3px;
overflow:hidden;
float:left;
}
[pseudo-radio] .option{
padding:5px;
background:#777;
color:#fff;
text-decoration:none;
float:left;
margin-right:3px;
font-family:sans-serif;
}
[pseudo-radio] .option.active{
background:#333;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment