A Pen by Marcos Sandrini on CodePen.
Created
January 30, 2015 13:38
-
-
Save msandrini/b3bbd311faf876b44f69 to your computer and use it in GitHub Desktop.
Angular pseudo-radio 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"> | |
<div pseudo-radio | |
data-values="{1:'one', 2:'two', 3:'three'}" | |
data-model="myVar"></div> | |
</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('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; | |
} | |
} | |
} | |
}); |
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
[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