Added support for radio button directive. Fixes #97

This commit is contained in:
Max Lynch
2013-11-12 00:39:57 -06:00
parent 1627c242c4
commit d1e6f2e3ec
5 changed files with 185 additions and 9 deletions

View File

@ -0,0 +1,51 @@
(function(ionic) {
'use strict';
angular.module('ionic.ui.radio', [])
// The radio button is a radio powered element with only
// one possible selection in a set of options.
.directive('radio', function() {
return {
restrict: 'E',
replace: true,
require: '?ngModel',
scope: {
value: '@'
},
transclude: true,
template: '<label class="item item-radio">\
<input type="radio" name="group">\
<div class="item-content" ng-transclude>\
</div>\
<i class="radio-icon icon ion-checkmark"></i>\
</label>',
link: function($scope, $element, $attr, ngModel) {
var radio;
if(!ngModel) { return; }
radio = $element.children().eq(0);
if(!radio.length) { return; }
radio.bind('click', function(e) {
$scope.$apply(function() {
ngModel.$setViewValue($scope.$eval($attr.ngValue));
});
});
ngModel.$render = function() {
var val = $scope.$eval($attr.ngValue);
if(val === ngModel.$viewValue) {
radio.attr('checked', 'checked');
} else {
radio.removeAttr('checked');
}
};
}
};
});
})(window.ionic);

View File

@ -1,7 +1,10 @@
(function(ionic) {
'use strict';
angular.module('ionic.ui.toggle', [])
// The content directive is a core scrollable content area
// that is part of many View hierarchies
// The Toggle directive is a toggle switch that can be tapped to change
// its value
.directive('toggle', function() {
return {
restrict: 'E',
@ -39,3 +42,5 @@ angular.module('ionic.ui.toggle', [])
}
};
});
})(window.ionic);