加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

‘=?’的含义是什么?在angularJS指令隔离范围声明?

发布时间:2020-12-17 09:13:38 所属栏目:安全 来源:网络整理
导读:问号在等号后有特殊意义吗?即: scope: {foo: '=?'} 上面的意思是“如果’foo’无法解决,不会引发错误? Yes: The ‘isolate’ scope takes an object hash which defines a set of local scope properties derived from the parent scope. These local pr
问号在等号后有特殊意义吗?即:
scope: {foo: '=?'}

上面的意思是“如果’foo’无法解决,不会引发错误?

Yes:

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:

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

它应该在影响范围属性的每个摘要上触发预期的错误:

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]);
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读