Enables simple angular attribute directives. "Simple" because this can only handle DOM attributes, not blaze attributes. This rules out the possibility of handing down a function or any reactive attributes. None the less, there is still a big use case.
The following is an example usage from jandres:[email protected]:
import { TemplateAttributeDirectiveType } from 'meteor/jandres:template-attribute-directive';
let ionNavDirection = new TemplateAttributeDirectiveType('ionNavDirection', {
$postLink($scope, $element, $attr) {
$element.bind('click', function() {
// Note: ionnavdirection instead of ionNavDirection due
// to Node.attributes lowercasing.
$ionicViewSwitcher.nextDirection($attr.ionnavdirection);
});
}
});
export { ionNavDirection };
Then in somewhere in your template:
During constructor of the TemplateAttributeDirectiveType
you can pass:
- $preLink: Called while traversing downwards the template from root template.
- $postLink: Called while traversing upwards the template from leaf templates.
And in these, two hooks you are given:
- $scope: From
jandres:template-scope
which emulates angular $scope. - $element: The element in which the attribute is attached.
- $attr: The dictionary of attributes and their value (if any). This includes the current directive. There is only one problem, these will be lowercase. This will hopefully be addressed in the future.
That being said, you can emulate onDestroyed
callback via:
$scope.$on('$destroy', function() {
// Destroy stuff and what not.
});