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

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

问题描述

我通过新的NG-书工作我的方式。在过滤器本章包括定义带有以下code解析器一个部分:

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'语法,和角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]

它是用来指定哪些指令控制器应使用(继承自)。因此,例如指令<列项> 需要找到父控制器< CRTL网> 。有几个能与该属性被用于沿符号和它们也可以结合:

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:

^ =表示的角度寻求了DOM找到指令。

^ = 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.

所以?ngModel 是说,ngModel需要与该指令一起宣布。

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

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

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