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

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -