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

angularjs – “=? “在角度指令隔离范围

发布时间:2020-12-17 09:16:31 所属栏目:安全 来源:网络整理
导读:scope: { someProperty: "=?" somePropertyTwo: =?Wheeeeee} 什么是“=?”做?我无法在任何地方找到答案.我理解使用范围:{}(或范围:true)为指令赋予一个新的范围,前者是一个隔离范围,后者是单向绑定到父Ctrl(指向页面/视图的Ctrl)用来).我明白那个: some
scope: {
    someProperty: "=?"
    somePropertyTwo: =?Wheeeeee
}

什么是“=?”做?我无法在任何地方找到答案.我理解使用范围:{}(或范围:true)为指令赋予一个新的范围,前者是一个隔离范围,后者是单向绑定到父Ctrl(指向页面/视图的Ctrl)用来).我明白那个:

someProp: @X //will one-way bind someProp to parent Ctrl's X
someProp: =X //two-way
someProp: &X() //some space magic for binding methods

但是,我不明白为什么/为什么使用“=?”.

相关文章(仅涵盖前三个):
http://www.undefinednull.com/2014/02/11/mastering-the-scope-of-a-directive-in-angularjs/
http://weblogs.asp.net/dwahlin/creating-custom-angularjs-directives-part-2-isolate-scope

编辑:这些是一样的吗?

? – 尝试找到所需的控制器或将null传递给链接fn(如果未找到).
^ – 通过搜索元素及其父元素来定位所需的控制器.如果找不到则抛出错误.
https://docs.angularjs.org/api/ng/service/ $#编译-require-

即如果找不到任何属性,则传递null?

它只是意味着双向绑定是可选的.如果使用=定义属性,则必须为其提供有效绑定.来自$compile documentation:

(…) 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. If you
want to shallow watch for changes (i.e. $watchCollection instead of
$watch) you can use =* or =attr (=? or =*?attr if the property is optional).

(编辑:李大同)

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

    推荐文章
      热点阅读