mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-08 15:51:16 +08:00
Added support for radio button directive. Fixes #97
This commit is contained in:
51
js/ext/angular/src/directive/ionicRadio.js
vendored
Normal file
51
js/ext/angular/src/directive/ionicRadio.js
vendored
Normal 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);
|
||||
9
js/ext/angular/src/directive/ionicToggle.js
vendored
9
js/ext/angular/src/directive/ionicToggle.js
vendored
@ -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);
|
||||
|
||||
Reference in New Issue
Block a user