I'm a new-be to Javascript and AnuglarJS but I have some Java experience. I'm studying AngularJS developer's guide on directive and have a question.
In the section "Creating a Directive that Wraps Other Elements" there is a example/demo. In the example/demo:
The template of the directive myDialog is as bellow:
<div class="alert">
<a href class="close" ng-click="close({message: 'closing for now'})">×</a>
<div ng-transclude></div>
</div>
I cannot understand close({message: 'closing for now'}) here. From the directive's definition:
scope: {
'close': '&onClose'
}
So close is a reference to onClose in the directive's parent. onClose is not defined in the controller but appears in it's template as an attribute and further refer to hideDialog(message):
<div ng-controller="Controller">
{{message}}
<my-dialog ng-hide="dialogIsHidden" on-close="hideDialog(message)">
Check out the contents, {{name}}!
</my-dialog>
</div>
Questions:
- Since
onCloseis not specifically defined in the controller, how can it take and process any input parameter passed from the directive? hideDialogin the controller takes a string parameter, butclosein the directive passes an object{message: 'closing for now'}toonClose. howonClosedoes the magic of extracting the value from themessagekey of the input and passing it to the target functionhideDialog?