什么意思'=?'在angularJS指令隔离声明范围? [英] what's the meaning of '=?' in angularJS directive isolate scope declaration?
问题描述
请问等号后的问号具有特殊含义?即:
Does the question mark after equals have special meaning? ie:
scope: {foo: '=?'}
在不高于平均不养错误,如果'富'不能得到解决?
does the above mean 'do not raise error if 'foo' cannot be resolved?
推荐答案
在'隔离'范围将对象的哈希它定义了一组从父范围派生局部范围的属性。这些本地属性为模板混叠值非常有用。当地人的定义是本地范围属性源的哈希值:
The 'isolate' scope takes an object hash which defines a set of local scope properties derived from the parent scope. These local properties are useful for aliasing values for templates. Locals definition is a hash of local scope property to its source:
=
或 =属性
- 建立一个本地范围之间的双向绑定
财产和通过价值定义名称的父作用域属性
的 ATTR
属性。如果没有指定 ATTR
名称,则
属性名称被假定为相同的本地名称。特定
<小部件我-ATTR =parentModel>
和范围部件定义:{
,然后部件scope属性
localModel:'= myAttr'} localModel
将
反映 parentModel
的父范围值。任何改变
parentModel
将在 localModel
中反映出来,并在任何改变
localModel
将反映 parentModel
。 如果父作用域
属性不存在,它会抛出一个
NON_ASSIGNABLE_MODEL_EX preSSION例外。您可避免此行为
使用 = <?/ code>或
=?ATTR
为标志的属性作为可选的。
=
or =attr
- set up bi-directional binding between a local scope
property and the parent scope property of name defined via the value
of the attr
attribute. If no attr
name is specified then the
attribute name is assumed to be the same as the local name. Given
<widget my-attr="parentModel">
and widget definition of scope: {
localModel:'=myAttr' }
, then widget scope property localModel
will
reflect the value of parentModel
on the parent scope. Any changes to
parentModel
will be reflected in localModel
and any changes in
localModel
will reflect in parentModel
. If the parent scope
property doesn't exist, it will throw a
NON_ASSIGNABLE_MODEL_EXPRESSION exception. You can avoid this behavior
using =?
or =?attr
in order to flag the property as optional.
应该触发预期误差在每个消化影响的范围属性:
It should trigger the expected error on every digest that affects the scope property:
parentSet = parentGet.assign || function() {
// reset the change, or we will throw this exception on every $digest
lastValue = scope[scopeName] = parentGet(parentScope);
throw Error(NON_ASSIGNABLE_MODEL_EXPRESSION + attrs[attrName] +
' (directive: ' + newScopeDirective.name + ')');
};
//...
if (parentValue !== scope[scopeName]) {
// we are out of sync and need to copy
if (parentValue !== lastValue) {
// parent changed and it has precedence
lastValue = scope[scopeName] = parentValue;
} else {
// if the parent can be assigned then do so
parentSet(parentScope, lastValue = scope[scopeName]);
}
}
这篇关于什么意思'=?'在angularJS指令隔离声明范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!