“ =”是什么意思?在angularJS指令隔离范围声明?

尼基塔

等问后的问号有特殊含义吗?即:

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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章