等问后的问号有特殊含义吗?即:
scope: {foo: '=?'}
上面的意思是“无法解决'foo'时不引发错误?”
“隔离”范围采用对象散列,该对象散列定义了一组从父范围派生的局部范围属性。这些本地属性对于模板的别名值很有用。本地定义是本地范围属性与其源的哈希值:
=
或=attr
-在本地范围属性和通过attr
属性值定义的名称的父范围属性之间建立双向绑定。如果未attr
指定名称,则假定属性名称与本地名称相同。给定<widget my-attr="parentModel">
和的窗口小部件定义scope: { localModel:'=myAttr' }
,则窗口小部件作用域属性localModel
将反映parentModel
父作用域上的值。对的任何更改parentModel
将反映在中localModel
,对的任何更改localModel
将反映在中parentModel
。如果父范围属性不存在,它将抛出NON_ASSIGNABLE_MODEL_EXPRESSION异常。您可以使用=?
或=?attr
为了将属性标记为可选,来避免这种行为。
它应该在影响范围属性的每个摘要上触发预期的错误:
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]);
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句