I am using NgSwitchery to style my checkbox in ios style in my angularjs app.
Problem: I want to ask the user to confirm the action if he/she clicks on the switch. Example: If the switch is in true state and user clicks it, a popup should ask the user to confirm this action. If the user says yes then only the state should be changed.
Code: Added this directive code to the angular app.
.directive('ngConfirmClick', [
function(){
return {
priority: 10,
restrict: 'A',
link: function(scope, element, attrs){
element.bind('click', function(e){
var message = attrs.ngConfirmClick;
if(message && !confirm(message)){
e.stopImmediatePropagation();
e.preventDefault();
}
});
}
}
])
<input type="checkbox" ng-confirm-click ng-model="switches.basic"
ui-switch="{color: '#2ccb75', secondaryColor: '#fa9191'}" />
Link to plunker
Aucun commentaire:
Enregistrer un commentaire