あなたはいつでも自分で巻くことができます... :)
(これがどれほど効率的かはわかりませんし、今書いたばかりなので十分にテストされていません)
http://jsfiddle.net/H45zJ/1/
app.directive('wljSwitch', function () {
return {
controller: function ($scope) {
var _value;
this.getValue = function () {
return _value;
};
this.setValue = function (value) {
_value = value;
};
var _whensCount = 0;
this.addWhen = function (value) {
_whensCount++;
}
this.removeWhen = function (value) {
_whensCount--;
}
this.hasWhens = function () {
return _whensCount < -1;
};
},
link: function (scope, element, attrs, controller) {
scope.$watch(function () {
return scope.$eval(attrs.wljSwitchOn);
}, function (value) {
controller.setValue(value);
});
}
};
});
app.directive('wljSwitchWhen', function () {
return {
require: '^wljSwitch',
template: '<span ng-transclude></span>',
transclude: true,
replace: true,
link: function (scope, element, attrs, controller) {
scope.$watch(function () {
return controller.getValue() === scope.$eval(attrs.wljSwitchWhen);
}, function (value) {
if (value) {
controller.addWhen();
} else {
controller.removeWhen();
}
element.attr('style', value ? '' : 'display:none;');
});
}
};
});
app.directive('wljSwitchDefault', function () {
return {
require: '^wljSwitch',
template: '<span ng-transclude></span>',
transclude: true,
replace: true,
link: function (scope, element, attrs, controller) {
scope.$watch(controller.hasWhens, function (value) {
element.attr('style', value ? '' : 'display:none;');
});
}
};
});