最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - When and why to use &?, =?, @? in AngularJS? - Stack Overflow

programmeradmin0浏览0评论

I followed some tutorials to create angular directives. In the isolate scope, some tutorials define scope like this:

scope: {
  model: '=?',
  data:  '@?' 
}

Meanwhile, some tutorials define scope without question mark like this:

scope: {
  model: '=',
  data:  '@'
}

Can anybody explain me the difference or the purpose of these with examples? Thank you.

I followed some tutorials to create angular directives. In the isolate scope, some tutorials define scope like this:

scope: {
  model: '=?',
  data:  '@?' 
}

Meanwhile, some tutorials define scope without question mark like this:

scope: {
  model: '=',
  data:  '@'
}

Can anybody explain me the difference or the purpose of these with examples? Thank you.

Share Improve this question edited Apr 27, 2019 at 18:30 Daniel Cottone 4,48029 silver badges39 bronze badges asked Jul 23, 2015 at 13:47 ShaohaoShaohao 3,5117 gold badges27 silver badges45 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 14

The &, @, and = symbols are used to define the bindings (one-way, bi-directional, etc) for isolated scope objects, as you already know. Here is a pretty thorough tutorial on how all this works.

The ? symbol is used to indicate that the parent scope property to which the isolated scope binding refers to is optional. This means that if for some reason the parent scope property doesn't exist, then your application will continue to run without throwing the NON_ASSIGNABLE_MODEL_EXPRESSION exception.

发布评论

评论列表(0)

  1. 暂无评论