# ng1-decorators

> This is a small angular decorator collection to easily separate your code from angular. On the given class creates a static factory method for angular. It gets the dependencies from the constructor and provide it to the angular injector.

Latest version **3.1.2** (published 2015-12-16) · ISC license · 0 weekly downloads

## Install

```sh
npm install ng1-decorators
pnpm add ng1-decorators
yarn add ng1-decorators
bun add ng1-decorators
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.2 |
| Published | 2015-12-16 |
| First published | 2015-12-13 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Viktor Somodi |
| Maintainers | sviktor |

## Links

- npm: https://www.npmjs.com/package/ng1-decorators
- Repository: https://github.com/Valetudox/ng1-decorators
- Homepage: https://github.com/Valetudox/ng1-decorators#readme
- Issues: https://github.com/Valetudox/ng1-decorators/issues
- npm.io page: https://npm.io/package/ng1-decorators

## Dependencies (2)

- [deep-extend](https://npm.io/package/deep-extend.md) ^0.4.0
- [get-parameter-names](https://npm.io/package/get-parameter-names.md) ^0.2.0

## Recent versions

- 3.1.2 (latest) — 2015-12-16
- 3.1.1 — 2015-12-16
- 3.1.0 — 2015-12-16
- 3.0.0 — 2015-12-14
- 2.5.1 — 2015-12-14
- 2.5.0 — 2015-12-14
- 2.4.0 — 2015-12-14
- 2.3.0 — 2015-12-14
- 2.2.0 — 2015-12-14
- 2.1.1 — 2015-12-14
- 2.1.0 — 2015-12-14
- 2.0.0 — 2015-12-14
- 1.0.4 — 2015-12-14
- 1.0.3 — 2015-12-13
- 1.0.2 — 2015-12-13
- … 2 more at https://npm.io/package/ng1-decorators/versions

## README

#Angular 1 Decorators

This is a small angular decorator collection to easily separate your code from angular. On the given class creates 
a static factory method for angular. It gets the dependencies from the constructor and provide it to the angular injector. 

```bash
npm install --save ng1-decorators
```

## Setup
 
Add Babel stage-1 to your babelrc as preset

## Filters

A Filter (Pipe) class should have a transform function!

###Class

```javascript
const Pipe = require('ng1-decorators').Pipe;

@Pipe
class CustomPipe {
    constructor(dep1, dep2) {
        this._dep1 = dep1;
        this._dep2 = dep2;
        this.transform = this.transform.bind(this;
    }

    transform(input) {
        return this._input + this._dep1 + this._dep2;
    }

}
```

###Angular module

```javascript
angular
    .module('test', [])
    .filter('customer', CustomPipe.create());
```

###Created Factory Method
```javascript
CustomPipe.create = () => {
    return ['dep1', 'dep2', (dep1, dep2) => {
      return (new Pipe(dep1, dep2)).transform;
    }];
};
```


##Services

###Class
```javascript
const Service = require('ng1-decorators').Service;

@Service
class CustomService {
    constructor(dep1) {
        this._dep1 = dep1;
    }

    method() {
        return this._dep1 + 'yo!';
    }

}
```

###Angular module
```javascript
angular
    .module('test', [])
    .service('custom', CustomService.create());
```

###Created Factory Method
```javascript
CustomService.create = () => {
    return ['dep1', 'dep2', CustomService];
};
```

##Directives

###Class
```javascript
const Directive = require('ng1-decorators').Directive;

@Directive({
    template: '<div>hello</div>',
    scope: {
        input1: '@',
        input2: '@'
    },
    link: (element, scope, attributes, ctrl) => {
        ctrl.addElement(element);
    }
}
})
class CustomDirective {
    constructor(dep1) {
        this._dep1 = dep1;
        this._element = null;
    }

    addElement(element) {
        this._element = element;
    }

    method() {
        return this._dep1 + 'yo!';
    }

}
```
###Defaults
```javascript
{
  restrict: 'E',
  replace: false,
  bindToController: true,
  controllerAs: 'ctrl'
}
```


###Angular module
```javascript
angular
    .module('test', [])
    .directive('custom', CustomDirective.create());
```

###Created Factory Method
```javascript
CustomDirective.create = () => {
    return () => ({
        restrict: 'E',
        replace: false,
        bindToController: true,
        controllerAs: 'ctrl',
        controller: ['dep1', CustomDirective], 
        template: '<div>hello</div>',
        scope: {
            input1: '@',
            input2: '@'
        },
        link: (element, scope, attributes, ctrl) => {
            ctrl.addElement(element);
        });
    };
};
```

---
_Source: https://npm.io/package/ng1-decorators · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
