AngularJS Live Example
HTML
<div ng-app="App">
<div ng-controller="ParentCtrl">
<input type="checkbox" ng-model="foo">
<mobilecheckbox value="foo" title="title"></mobilecheckbox>
</div>
</div>
CSS
</style>
<script src="http://code.angularjs.org/1.0.0rc9/angular-1.0.0rc9.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.css"/>
<style>
JavaScript
var App = angular.module('App',[])
.directive('mobilecheckbox', function() {
return {
restrict: 'E',
replace: true,
template:
'<div class="ui-checkbox">'+
'<label class="ui-btn ui-btn-corner-all ui-btn-icon-left ui-checkbox-off ui-btn-up-c">'+
'<span class="ui-btn-inner ui-btn-corner-all">'+
'<span class="ui-btn-text">{{title()}}</span>'+
'<span class="ui-icon ui-icon-shadow" ng-class="{\'ui-icon-checkbox-on\': value(), \'ui-icon-checkbox-off\': !value()}"> </span>'+
'</span>'+
'</label>'+
'</div>',
link: function(scope, element, attrs, controller) {
element.bind('click', function() {
scope.$apply(function(){
scope.value(!scope.value());
});
});
},
scope: {
value: 'accessor',
title: 'accessor'
}
}
});
function ParentCtrl($scope){
$scope.foo= false;
$scope.title = "Checkbox title";
}