diff --git a/README.md b/README.md index c7400e3..209326a 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,22 @@ Add optional on/off text ``` +Add custom values for `ON` / `OFF` (if your model is not based on true/false values) +```html +
+ +
{{ enabled }} +
+``` + +Add a custom method to `on-click` event +```html +
+ +
{{ enabled }} +
+``` + Disabled state ```html
diff --git a/angular-ui-switch.js b/angular-ui-switch.js index 9a6b591..6b77397 100644 --- a/angular-ui-switch.js +++ b/angular-ui-switch.js @@ -7,10 +7,26 @@ angular.module('uiSwitch', []) , transclude: true , template: function(element, attrs) { var html = ''; + var extraMethod = ''; + + if (attrs.ngOnClick) { + extraMethod += '; ' + attrs.ngOnClick; + } + if (attrs.ngChange) { + extraMethod += '; ' + attrs.ngChange + '()'; + } + html += ''+e.on+"":"",s+=e.off?''+e.off+"":" ",s+=""}}}); \ No newline at end of file +angular.module("uiSwitch",[]).directive("switch",function(){return{restrict:"AE",replace:!0,transclude:!0,template:function(e,n){var l="",a="";return n.ngOnClick&&(a+="; "+n.ngOnClick),n.ngChange&&(a+="; "+n.ngChange+"()"),l+="'+n.on+"":"",l+=n.off?''+n.off+"":" ",l+=""}}});