Reputation: 105517
I understand the technical difference between using =
and &
in isolated scopes in terms of what is assigned to isolate scope property:
// "="
isolateScopeProperty = getter(parentScope)
// "&"
isolateScopeProperty = function(locals) {
getter(parentScope, locals);
}
But when explaining the difference to people I can't really come up with a good example. Do you know any good examples?
Upvotes: 1
Views: 49
Reputation: 3644
Use case Infinite-Scroll-Directive
a) have a scope property =currentPage, to get (or set) the current page the infinite scroll is at.
b) have a scope property &loadContent, to provide a callback to load data for the next page to add to the infinite scroll.
Upvotes: 1
Reputation: 1643
I would recommend you to watch this egghead video tutorial.
& 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. Video of & 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 and propagated to the parent and vice-versa. Video of = is here: https://egghead.io/lessons/angularjs-isolate-scope-two-way-binding.
Check this to Difference of &
and =
Upvotes: 2