Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/gbbr/ngnode

AngularJS Directive Helper service
https://github.com/gbbr/ngnode

Last synced: about 1 month ago
JSON representation

AngularJS Directive Helper service

Awesome Lists containing this project

README

        

## ngNode
#### Lightweight directive helper service

Provides the $node helper service to directives for easy access to DOM Elements in their templates.

To use, add the `ng-node` attribute to the desired HTML Elements and pass the desired $node property name as value.
For example, using `ng-node="btnCancel` will make `$node.btnCancel` available on the service for the directive.

Improves mainainability and readibility. Helps leave out redundant DOM queries.

__HTML__

```html


Home



Contact


```

__JS__

```js
angular.module('myModule', ['ngNode']);
angular.module('myModule').directive('myDirective', function($node) {
/* ... */
return {
restrict: 'E',
link: function() {
$node.btnHome.on('click', goHome);
$node.btnContact.on('click', showContact);
$node.txtOutput.html('Hello world!');
}
}
});
```

WARNING: Do not use within controllers. DOM Manipulation should only be done in directives according to AngularJS best practices.