0

when I use '=' to pass a function, it works fine. But why the '&' exsits? Is it just let it look like an event?

xlhuang
  • 221
  • 2
  • 9

1 Answers1

1

Attribute's interpolation: @

@ indicates to AngularJS that should interpolate the value of the specified attribute (the value in the isolated scope changes if the attribute's value changes).

Binding data to the attribute: =

= indicates to AngularJS that should keep the expression of the specified attribute (the value in the isolated scope changes if the attribute's expression changes).

Providing a callback: &

& indicates to AngularJS that the expression specified in the attribute will be avaliable on the isolated scope as a function that will execute the expression. Use this option to create callbacks.

http://codepen.io/ces/pen/ZGOLOq

Community
  • 1
  • 1
cespon
  • 5,630
  • 7
  • 33
  • 47
  • Is there any time we can't use '=' but can use '&' – xlhuang May 18 '15 at 07:21
  • I think no. But if you need to use variables from parent scope is simpler passing only a callback function (using `&`) that passing the function and all the variables that you need to directive (using `=`). http://codepen.io/ces/pen/xGOLdg – cespon May 18 '15 at 08:56
  • You have more examples and information here: http://stackoverflow.com/questions/14050195/what-is-the-difference-between-and-in-directive-scope – cespon May 18 '15 at 09:05