Angular where one of two attributes is required
1 answer
You need to pass them as an array of strings.
You cannot tell Angular that at least one of these requirements should be available, so set them as optional and check the communication function if one is available. Update your code to:
app.directive('myDir', function () {
return {
require: ['?ngModel', '?kNgModel'],
link: function(scope, element, attrs, controllers){
if(!controllers[0] && !controllers[1]){
throw 'myDir expects either ng-model or k-ng-model to be defined';
}
}
};
});
+3
source to share