# ng-injector

> Injector decorator for writing angular 1.x with ES6/TypeScript

Latest version **0.4.5** (published 2016-07-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install ng-injector
pnpm add ng-injector
yarn add ng-injector
bun add ng-injector
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.5 |
| Published | 2016-07-18 |
| First published | 2016-03-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | lynweklm@gmail.com |
| Maintainers | broooooklyn |
| Keywords | Angular, Angular.js, Angularjs, Injector, Decorator |

## Links

- npm: https://www.npmjs.com/package/ng-injector
- Repository: https://github.com/Brooooooklyn/angular1.x-injector
- Homepage: https://github.com/Brooooooklyn/angular1.x-injector#readme
- Issues: https://github.com/Brooooooklyn/angular1.x-injector/issues
- npm.io page: https://npm.io/package/ng-injector

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 0.4.5 (latest) — 2016-07-18
- 0.4.4 — 2016-05-12
- 0.4.3 — 2016-05-12
- 0.4.2 — 2016-04-11
- 0.4.1 — 2016-04-10
- 0.4.0 — 2016-04-10
- 0.3.0 — 2016-03-30
- 0.2.2 — 2016-03-30
- 0.2.1 — 2016-03-29
- 0.2.0 — 2016-03-29
- 0.1.0 — 2016-03-27

## README

# What's this
Injector Decorator for Angular 1.x
It's useful when your are writing Angular 1.x application in ES2015 or TypeScript

## Install
```
npm i ng-injector --save
```

## usage

### es2015
user_service.js
```js
'use strict'

import {injector} from 'ng-injector'
@injector([
  '$q'
])
export class UserService {
  getAppName() {
    return this.$q.resolve('teambition!')
  }
}
```
home_view.js
```js
'use strict'
import {injector} from 'ng-injector'

@injector([
  '$timeout',
  'UserService'
])
export class HomeView {
  constructor() {
    this.$timeout(() => this.title = 'HomeView', 100)
    this.UserService
      .getAppName()
      .then(appName => {
        this.appName = appName
      })
  }
}
```
home.html

```html
<div ng-controller="HomeView as HomeCtrl">
  <span class="title">{{HomeCtrl.title}}</span>
  <span class="app-name">{{HomeCtrl.appName}}</span>
</div>

```

app.js
```js
'use strict'
import {HomeView} from './home_view'
import {UserService} from './user_service'
angular.module('YourModuleName', [])
  .service('UserService', UserService)
  .controller('HomeView', HomeView)
```

### TypeScript

user_service.ts
```ts
'use strict'

import {injector} from 'ng-injector'
@injector([
  '$q'
])
export class UserService {

  private $q: angular.IQService

  getAppName() {
    return this.$q.resolve('teambition!')
  }
}
```

home_view.ts
```ts
'use strict'
import {injector} from 'ng-injector'
import {UserService} from './user_service'

@injector([
  '$timeout',
  'UserService'
])
export class HomeView {

  public appName: string

  private $timeout: angular.ITimeoutService
  private UserService: UserService

  constructor() {
    this.$timeout(() => this.title = 'HomeView', 100)
    this.UserService
      .getAppName()
      .then(appName => {
        this.appName = appName
      })
  }
}
```
home.html

```html
<div ng-controller="HomeView as HomeCtrl">
  <span class="title">{{HomeCtrl.title}}</span>
  <span class="app-name">{{HomeCtrl.appName}}</span>
</div>

```

app.ts
```ts
'use strict'
import {HomeView} from './home_view'
import {UserService} from './user_service'
angular.module('YourModuleName', [])
  .service('UserService', UserService)
  .controller('HomeView', HomeView)
```

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