Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the significance of '?ngModel' when creating an AngularJS directive?

I'm working my way through the new ng-book. The chapter on filters includes a section on defining parsers with the following code:

angular.module('myApp')
.directive('oneToTen', function() {
    return {
        require: '?ngModel';

The first time I've seen the '?ngModel' syntax, and the Angular API docs don't provide much help. What does this syntax signify?

Thanks!

like image 918
Brian Piercy Avatar asked Jan 02 '14 19:01

Brian Piercy


1 Answers

? is optional directive and ^ is parent directive

http://docs.angularjs.org/api/ng.$compile

(no prefix) - Locate the required controller on the current element. Throw an error if not found.
? - Attempt to locate the required controller or pass null to the link fn if not found.
^ - Locate the required controller by searching the element's parents. Throw an error if not found.
?^ - Attempt to locate the required controller by searching the element's parents or pass null to the link fn if not found.
like image 142
YOU Avatar answered Sep 22 '22 19:09

YOU