27.03.2017 Views

ng-book

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Introduction to Directives 73<br />

scope: {<br />

someProperty: '@'<br />

}<br />

Note that, by default, someProperty maps to the DOM attribute some-property. If we wanted to<br />

explicitly specify the name of the attribute we wanted to bind to, we could do so:<br />

scope: {<br />

someProperty: '@someAttr'<br />

}<br />

In this case, the HTML attribute would be named some-attr instead of some-property:<br />

<br />

<br />

Now, when we try to access someProperty inside our directive, for example in the directive’s<br />

template or controller (as we did above), we’ll receive the value copied from the DOM attribute:<br />

template: '\<br />

we have access to {{ someProperty }}\<br />

',<br />

controller: function($scope) {<br />

// a directive can have its own controller,<br />

// in which case we can fetch the<br />

// $scope.someProperty to be<br />

// "someProperty with @ bindi<strong>ng</strong>"<br />

}<br />

Back to our main example: to copy data from the DOM into the isolate scope of our directive, we<br />

use attributes:<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!