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?
(…) 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).