In angular.js, what does an ampersand in the directive mean?
Update: The new directive API is here
There is some more explanations on the Understanding Scopes doc, and they provide this useful link.
When I wanted to understand this stuff, I made a Fiddle.
angular.module('scopePropertiesModule', [])
.directive('scopeProps', function(){
return {
restrict: 'C',
scope: {parameterTitle:'@',
bidirecTitle:'=',
delegateDisplay:'&'},
template: '<div>' +
'Parameter title :<br>' +
'<input ng-model="parameterTitle"> => {{parameterTitle}}<br>'+
'<br>' +
'Biderectional title :<br>' +
'<input ng-model="bidirecTitle"> => {{bidirecTitle}}<br>' +
'<br>' +
'Delegate display :<br>' +
'{{delegateDisplay()}}<br>' +
'</div>'
}
});
and the markup:
<div class="scopeProps"
parameter-title="{{title}}"
bidirec-title="title"
delegate-display="displayTitle()"></div>
Feel free to play with it.
http://docs.angularjs.org/guide/directive (quick search for "scope")
From the docs:
& or &attr - provides a way to execute an expression in the context of the parent scope. If no attr name is specified then the attribute name is assumed to be the same as the local name. Given and widget definition of scope: { localFn:'&myAttr' }, then isolate scope property localFn will point to a function wrapper for the count = count + value expression. Often it's desirable to pass data from the isolated scope via an expression and to the parent scope, this can be done by passing a map of local variable names and values into the expression wrapper fn. For example, if the expression is increment(amount) then we can specify the amount value by calling the localFn as localFn({amount: 22}).