In this code:
app.directive( 'myCustomDirective', function() { return { restrict: 'EA', scope: { value: '=myCustomDirective', clickable: '&', editing: '=' }, template: '<span ng-click="handleClick()" ng-bind="value"></span>', ...
What does clickable: '&'
denote?
When I do find Angular documentation, I cannot understand it. It seems to be written in a catch-22 code that can be understood only by people who already understand what is being explained.
For example, I found this video, which apparently explains the & thing, but he may as well have been speaking Mandarin.
Locals definition is a hash of local scope property to its source: = or =attr - set up bi-directional binding between a local scope property and the parent scope property of name defined via the value of the attr attribute.
AngularJS directives are extended HTML attributes with the prefix ng- . The ng-app directive initializes an AngularJS application. The ng-init directive initializes application data. The ng-model directive binds the value of HTML controls (input, select, textarea) to application data.
What are Directives? At a high level, directives are markers on a DOM element (such as an attribute, element name, comment or CSS class) that tell AngularJS's HTML compiler ( $compile ) to attach a specified behavior to that DOM element (e.g. via event listeners), or even to transform the DOM element and its children.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With