angularjs - Angular directive where one of two attributes are required -
how write directive requires either ng-model
or k-ng-model
? documentation doesn't cover :(
app.directive('mydir', function () { return { require: 'ngmodel || kngmodel', // omitted }; });
you need pass them in array of strings.
you can't tell angular @ least 1 of these needs available, set them optional , check in link function if 1 of both available. update 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 defined'; } } }; });
Comments
Post a Comment