我正在学习新的 ng-book。关于过滤器的章节包括使用以下代码定义解析器的部分:
angular.module('myApp')
.directive('oneToTen', function() {
return {
require: '?ngModel';
我第一次看到 '?ngModel' 语法,Angular API 文档没有提供太多帮助。此语法表示什么?
谢谢!
最佳答案
?
是可选指令,^
是父指令
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.
关于javascript - 创建 AngularJS 指令时 '?ngModel' 的意义是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20890001/