0

I thought an equal sign means two way binding? As in I'd bring in a value of a camelCased attribute to my directive.

What does this = mean then? I'm looking over some more advanced code in a book

.directive('contentHandler', function () {
return {
  scope: {
    feed: '=contentHandler',
    onChange: '&'
  },

I see it again here:

return {
  scope: {
    value: '=debug'
  },

Here is the html associated with the first one:

<div content-handler="feed" on-change="onUpdate(element, action)">
SD Dev
  • 335
  • 3
  • 10

1 Answers1

2

The scope option is an object that contains a property for each isolate scope binding. In this case it has just one property:

Its name (customerInfo) corresponds to the directive's isolate scope property customerInfo.

Its value (=info) tells $compile to bind to the info attribute.

Note: These =attr attributes in the scope option of directives are normalized just like directive names. To bind to the attribute in , you'd specify a binding of =bindToThis. For cases where the attribute name is the same as the value you want to bind to inside the directive's scope, you can use this shorthand syntax:

scope: {
    // same as '=customer'
    customer: '='
},

https://docs.angularjs.org/guide/directive#isolating-the-scope-of-a-directive

Basically = sets up two-way binding between the directive's scope and the parent scope. Changes in the directive scope show up in the parent scope and changes in the parent scope show up in the directive's scope.

dave
  • 62,300
  • 5
  • 72
  • 93