I am very new to AngularJS. can anybody explain me the difference among these AngularJS operators: &, @ and =
when isolating scope with proper example.

- 7,753
- 14
- 53
- 96

- 7,823
- 7
- 38
- 45
-
1See also http://stackoverflow.com/questions/14050195/what-is-the-difference-between-and-in-directive-scope – Mark Rajcok Feb 16 '13 at 18:10
6 Answers
@
allows a value defined on the directive attribute to be passed to the directive's isolate scope. The value could be a simple string value (myattr="hello"
) or it could be an AngularJS interpolated string with embedded expressions (myattr="my_{{helloText}}"
). Think of it as "one-way" communication from the parent scope into the child directive. John Lindquist has a series of short screencasts explaining each of these. Screencast on @ is here: https://egghead.io/lessons/angularjs-isolate-scope-attribute-binding
&
allows the directive's isolate scope to pass values into the parent scope for evaluation in the expression defined in the attribute. Note that the directive attribute is implicitly an expression and does not use double curly brace expression syntax. This one is tougher to explain in text. Screencast on & is here: https://egghead.io/lessons/angularjs-isolate-scope-expression-binding
=
sets up a two-way binding expression between the directive's isolate scope and the parent scope. Changes in the child scope are propagated to the parent and vice-versa. Think of = as a combination of @ and &. Screencast on = is here: https://egghead.io/lessons/angularjs-isolate-scope-two-way-binding
And finally here is a screencast that shows all three used together in a single view: https://egghead.io/lessons/angularjs-isolate-scope-review

- 1,221
- 3
- 15
- 28

- 17,666
- 5
- 51
- 66
-
3The links to these appear to have changed, they are now: https://egghead.io/lessons/angularjs-isolate-scope-attribute-binding , https://egghead.io/lessons/angularjs-isolate-scope-expression-binding , https://egghead.io/lessons/angularjs-isolate-scope-two-way-binding , https://egghead.io/lessons/angularjs-isolate-scope-review , respectively. – Samih Oct 17 '14 at 10:35
-
1Thanks for the callout, I updated my answer with the correct URLs. – cliff.meyers Nov 19 '14 at 21:04
-
47It's a bit of a shame that the top rated answer links to videos behind a pay wall when there's probably a load of free content out there that contains the same info. – BenCr Sep 04 '15 at 09:44
-
-
9
-
Can the `@` be used if the expression is only given a value after some ajax request is complete? – rayray Apr 11 '19 at 14:45
-
I would like to explain the concepts from the perspective of JavaScript prototype inheritance. Hopefully help to understand.
There are three options to define the scope of a directive:
scope: false
: Angular default. The directive's scope is exactly the one of its parent scope (parentScope
).scope: true
: Angular creates a scope for this directive. The scope prototypically inherits fromparentScope
.scope: {...}
: isolated scope is explained below.
Specifying scope: {...}
defines an isolatedScope
. An isolatedScope
does not inherit properties from parentScope
, although isolatedScope.$parent === parentScope
. It is defined through:
app.directive("myDirective", function() {
return {
scope: {
... // defining scope means that 'no inheritance from parent'.
},
}
})
isolatedScope
does not have direct access to parentScope
. But sometimes the directive needs to communicate with the parentScope
. They communicate through @
, =
and &
. The topic about using symbols @
, =
and &
are talking about scenarios using isolatedScope
.
It is usually used for some common components shared by different pages, like Modals. An isolated scope prevents polluting the global scope and is easy to share among pages.
Here is a basic directive: http://jsfiddle.net/7t984sf9/5/. An image to illustrate is:
@
: one-way binding
@
simply passes the property from parentScope
to isolatedScope
. It is called one-way binding
, which means you cannot modify the value of parentScope
properties. If you are familiar with JavaScript inheritance, you can understand these two scenarios easily:
If the binding property is a primitive type, like
interpolatedProp
in the example: you can modifyinterpolatedProp
, butparentProp1
would not be changed. However, if you change the value ofparentProp1
,interpolatedProp
will be overwritten with the new value (when angular $digest).If the binding property is some object, like
parentObj
: since the one passed toisolatedScope
is a reference, modifying the value will trigger this error:TypeError: Cannot assign to read only property 'x' of {"x":1,"y":2}
=
: two-way binding
=
is called two-way binding
, which means any modification in childScope
will also update the value in parentScope
, and vice versa. This rule works for both primitives and objects. If you change the binding type of parentObj
to be =
, you will find that you can modify the value of parentObj.x
. A typical example is ngModel
.
&
: function binding
&
allows the directive to call some parentScope
function and pass in some value from the directive. For example, check JSFiddle: & in directive scope.
Define a clickable template in the directive like:
<div ng-click="vm.onCheck({valueFromDirective: vm.value + ' is from the directive'})">
And use the directive like:
<div my-checkbox value="vm.myValue" on-check="vm.myFunction(valueFromDirective)"></div>
The variable valueFromDirective
is passed from the directive to the parent controller through {valueFromDirective: ...
.
Reference: Understanding Scopes

- 9,430
- 11
- 44
- 95
-
By default, directives use shared scope. If directive has 'scope:true', then it uses inherited scope, in which child can see parent properties but parent cannot see child internal properties. – YuMei Jul 24 '15 at 18:27
-
1**AngularJS – Isolated Scopes – @ vs = vs &** ---------- Short examples with explanation are available at below link : http://www.codeforeach.com/angularjs/angularjs-isolated-scopes-vs-vs – Prashanth Jun 27 '17 at 17:25
Not my fiddle, but http://jsfiddle.net/maxisam/QrCXh/ shows the difference. The key piece is:
scope:{
/* NOTE: Normally I would set my attributes and bindings
to be the same name but I wanted to delineate between
parent and isolated scope. */
isolatedAttributeFoo:'@attributeFoo',
isolatedBindingFoo:'=bindingFoo',
isolatedExpressionFoo:'&'
}
@: one-way binding
=: two-way binding
&: function binding

- 1,011
- 9
- 10
-
6
-
-
If your heart's set on it, you could take the value from @ and cast is to an int/bool? Otherwise I'd just use = or – Shawson Nov 09 '18 at 13:54
AngularJS – Isolated Scopes – @ vs = vs &
Short examples with explanation are available at below link :
http://www.codeforeach.com/angularjs/angularjs-isolated-scopes-vs-vs
@ – one way binding
In directive:
scope : { nameValue : "@name" }
In view:
<my-widget name="{{nameFromParentScope}}"></my-widget>
= – two way binding
In directive:
scope : { nameValue : "=name" },
link : function(scope) {
scope.name = "Changing the value here will get reflected in parent scope value";
}
In view:
<my-widget name="{{nameFromParentScope}}"></my-widget>
& – Function call
In directive :
scope : { nameChange : "&" }
link : function(scope) {
scope.nameChange({newName:"NameFromIsolaltedScope"});
}
In view:
<my-widget nameChange="onNameChange(newName)"></my-widget>

- 914
- 10
- 7
It took me a hell of a long time to really get a handle on this. The key to me was in understanding that "@" is for stuff that you want evaluated in situ and passed through into the directive as a constant where "=" actually passes the object itself.
There's a nice blog post that explains this this at: http://blog.ramses.io/technical/AngularJS-the-difference-between-@-&-and-=-when-declaring-directives-using-isolate-scopes

- 16,187
- 14
- 79
- 133