' +
+ template: '
' +
+ '
' +
'' +
'' +
'' +
'
' +
'
',
compile: function(element, attrs) {
- if (!attrs.onLabel) { attrs.onLabel = toggleSwitchConfig.onLabel; }
- if (!attrs.offLabel) { attrs.offLabel = toggleSwitchConfig.offLabel; }
- if (!attrs.knobLabel) { attrs.knobLabel = toggleSwitchConfig.knobLabel; }
+ if (angular.isUndefined(attrs.onLabel)) { attrs.onLabel = toggleSwitchConfig.onLabel; }
+ if (angular.isUndefined(attrs.offLabel)) { attrs.offLabel = toggleSwitchConfig.offLabel; }
+ if (angular.isUndefined(attrs.knobLabel)) { attrs.knobLabel = toggleSwitchConfig.knobLabel; }
return this.link;
},
diff --git a/test/angular-toggle-switch.spec.js b/test/angular-toggle-switch.spec.js
index 677ac54..a42bac1 100644
--- a/test/angular-toggle-switch.spec.js
+++ b/test/angular-toggle-switch.spec.js
@@ -1,7 +1,10 @@
describe('Toggle Switch', function() {
- var $scope, $compile;
+ var $scope, $compile, isolateScope;
var baseTemplate = '
\n';
+ var emptyOnLabelTemplate = '
\n';
+ var emptyOffLabelTemplate = '
\n';
+ var emptyKnobLabelTemplate = '
\n';
var onLabelTemplate = '
\n';
var offLabelTemplate = '
\n';
var knobLabelTemplate = '
\n';
@@ -22,6 +25,7 @@ describe('Toggle Switch', function() {
var elm = angular.element(template);
$compile(elm)(scope);
scope.$apply();
+ isolateScope = elm.isolateScope();
return elm;
}
@@ -96,6 +100,13 @@ describe('Toggle Switch', function() {
});
});
+ describe('with an empty `on-label`', function() {
+ it('sets the label empty', function() {
+ var elm = compileDirective(emptyOnLabelTemplate, $scope);
+ expect(isolateScope.onLabel).toEqual('');
+ });
+ });
+
describe('when there is a custom `off-label`', function () {
// @TODO: figure out how to deal with html in Angular 1.2
//describe('is html', function() {
@@ -113,6 +124,13 @@ describe('Toggle Switch', function() {
});
});
+ describe('with an empty `off-label`', function() {
+ it('sets the label empty', function() {
+ var elm = compileDirective(emptyOffLabelTemplate, $scope);
+ expect(isolateScope.offLabel).toEqual('');
+ });
+ });
+
describe('when there is a custom `knob-label`', function () {
it('sets the on label', function() {
var elm = compileDirective(knobLabelTemplate, $scope);
@@ -120,6 +138,13 @@ describe('Toggle Switch', function() {
});
});
+ describe('with an empty `knob-label`', function() {
+ it('sets the label empty', function() {
+ var elm = compileDirective(emptyKnobLabelTemplate, $scope);
+ expect(isolateScope.knobLabel).toEqual('');
+ });
+ });
+
describe('when toggle is disabled', function() {
it('ngModel does not change on click', function() {
$scope.switchState = true;