创建 AngularJS 指令时“?ngModel"的意义是什么? [英] What is the significance of '?ngModel' when creating an AngularJS directive?

查看:27
本文介绍了创建 AngularJS 指令时“?ngModel"的意义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习新的 ng-book.关于过滤器的章节包括使用以下代码定义解析器的部分:

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';

我第一次看到 '?ngModel' 语法,Angular API 文档并没有提供太多帮助.这个语法是什么意思?

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

谢谢!

推荐答案

必需可以解释为:

[?][^][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:

^ = 表示 angular 查找 DOM 以找到指令.

^ = it indicates angular to seek up the DOM to find the directive.

?= 表示 angular 该指令是可选的,如果没有找到,angular 不会抛出异常.

? = it indicates angular that the directive is optional and angular will not throw an exception if not found.

所以 ?ngModel 是说 ngModel 需要与该指令一起声明.

So ?ngModel is saying that the ngModel needs be declared along with this directive.

这篇关于创建 AngularJS 指令时“?ngModel"的意义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆