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', fu
Solution 1:
?
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 errorifnot found.
? - Attempt to locate the required controller or pass null to the link fn ifnot 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.
Solution 2:
The Required can be explained as:
[?][^][directiveName]
.
It is used to specify which directive controller should be used("inherited from"). So for instance a directive <column-item>
needs to find the parent controller <crtl-grid>
. There are a couple of symbols that can be used along with this attribute and they can also be combined:
^ = it indicates angular to seek up the DOM to find the directive.
? = it indicates angular that the directive is optional and angular will not throw an exception if not found.
So ?ngModel is saying that the ngModel needs be declared along with this directive.
Post a Comment for "What Is The Significance Of '?ngmodel' When Creating An Angularjs Directive?"