Skip to content

Instantly share code, notes, and snippets.

@artishan
Created August 2, 2015 11:48
Show Gist options
  • Save artishan/15698729a7fd81888d67 to your computer and use it in GitHub Desktop.
Save artishan/15698729a7fd81888d67 to your computer and use it in GitHub Desktop.
Simple ion-check-radio directive
/**
* @ngdoc directive
* @name ionCheckRadio
* @module ionic.checkRadio
* @restrict E
* @description
* Ionic checkbox style directive.
*
* @usage
* ```html
* <ion-check-radio ng-model="choice" ng-value="'A'">Choose A</ion-check-radio>
* <ion-check-radio ng-model="choice" ng-value="'B'">Choose B</ion-check-radio>
* <ion-check-radio ng-model="choice" ng-value="'C'">Choose C</ion-check-radio>
* ```
*
* @param {string=} name The name of the radio input.
* @param {expression=} value The value of the radio input.
* @param {expression=} ng-value Angular equivalent of the value attribute.
* @param {expression=} ng-model The angular model for the radio input.
*/
angular.module('ionic.checkRadio', []).directive('ionCheckRadio', function() {
return {
restrict: 'E',
replace: true,
require: '?ngModel',
transclude: true,
template:
'<label class="item item-checkbox">' +
'<div class="checkbox checkbox-input-hidden disable-pointer-events">' +
'<input type="radio">' +
'<i class="checkbox-icon"></i>' +
'</div>' +
'<div class="item-content disable-pointer-events" ng-transclude></div>' +
'</label>',
compile: function(element, attr) {
var input = element.find('input');
angular.forEach({
'name': attr.name,
'value': attr.value,
'ng-value': attr.ngValue,
'ng-model': attr.ngModel
}, function(value, name) {
if (value !== undefined) {
input.attr(name, value);
}
});
return function(scope, element, attr) {
scope.getValue = function() {
return scope.ngValue || attr.value;
};
};
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment