# ngcomponent

> A clean React-like abstraction for rendering non-Angular components within an Angular app.

Latest version **4.1.0** (published 2017-11-18) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install ngcomponent
pnpm add ngcomponent
yarn add ngcomponent
bun add ngcomponent
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.1.0 |
| Published | 2017-11-18 |
| First published | 2016-09-19 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+10 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 16 |
| Author | Boris Cherny |
| Maintainers | bcherny, khoomeister |
| Keywords | angular, component, react, directive, props, state, controller |

## Links

- npm: https://www.npmjs.com/package/ngcomponent
- Repository: https://github.com/coatue-oss/ngcomponent
- Homepage: https://github.com/coatue-oss/ngcomponent#readme
- Issues: https://github.com/coatue-oss/ngcomponent/issues
- npm.io page: https://npm.io/package/ngcomponent

## Dependencies (4)

- [lodash](https://npm.io/package/lodash.md) ^4.17.4
- [angular](https://npm.io/package/angular.md) >=1.5.0
- [@types/lodash](https://npm.io/package/@types/lodash.md) ^4.14.85
- [@types/angular](https://npm.io/package/@types/angular.md) ^1.6.39

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 4.1.0 (latest) — 2017-11-18
- 4.0.3 — 2017-11-18
- 4.0.2 — 2017-10-02
- 4.0.1 — 2017-09-26
- 4.0.0 — 2017-09-26
- 3.0.3 — 2017-09-15
- 3.0.2 — 2017-07-12
- 3.0.1 — 2017-04-27
- 3.0.0 — 2017-04-12
- 2.0.5 — 2017-03-22
- 2.0.4 — 2017-03-21
- 2.0.3 — 2017-03-18
- 2.0.2 — 2017-03-16
- 2.0.1 — 2017-03-16
- 1.1.3 — 2017-03-13
- … 3 more at https://npm.io/package/ngcomponent/versions

## README

# NgComponent [![Build Status][build]](https://circleci.com/gh/coatue-oss/ngcomponent) [![npm]](https://www.npmjs.com/package/ngcomponent) [![mit]](https://opensource.org/licenses/MIT)

[build]: https://img.shields.io/circleci/project/coatue-oss/ngcomponent.svg?branch=master&style=flat-square
[npm]: https://img.shields.io/npm/v/ngcomponent.svg?style=flat-square
[mit]: https://img.shields.io/npm/l/ngcomponent.svg?style=flat-square

> A clean React-like abstraction for rendering non-Angular components within an Angular app.

## Installation

```sh
# Using Yarn:
yarn add ngcomponent angular angular-resource

# Or, using NPM:
npm install ngcomponent angular angular-resource --save
```

## Usage

*Note: This example is in TypeScript, but it works just as well in vanilla JavaScript*

```ts
import NgComponent from 'ngcomponent'

interface Props {
  foo: number
  bar: string[]
}

interface State {}

const myComponent = {
  bindings: {
    foo: '<',
    bar: '<'
  },
  template: `
    <div></div>
  `,
  controller: class extends NgComponent<Props, State> {
    ...
  }
}
```

## Full Example

```ts
import NgComponent from 'ngcomponent'

interface Props {
  data: number[]
  type: "bar"|"line"
}

interface State {
  chart: Chart
}

const chartJSWrapper = {
  bindings: {
    data: '<',
    type: '<'
  },
  template: `<canvas></canvas>`,
  constructor(private $element: JQuery){}
  controller: class extends NgComponent<Props, State> {

    componentDidMount() {
      this.state.chart = new Chart($element.find('canvas'), {
        data: props.data,
        type: props.type
      })
    }

    render() {
      this.state.chart.data = this.props.data
      this.state.chart.type = this.props.type
      this.state.chart.update()
    }

    componentWillUnmount() {
      this.state.chart.destroy()
    }
  }
}
```

## Lifecycle Hooks

NgComponent has a React-like component lifecycle API:

- `render()` (use this to react to changes to `this.props`)
- `componentWillMount()`
- `componentDidMount()`
- `componentWillReceiveProps(props)`
- `shouldComponentUpdate(props, state)`
- `componentWillUpdate(props, state)`
- `componentDidUpdate(props, state)`
- `componentWillUnmount()`

## Running the Tests

```sh
npm test
```

## Hacking On It

```sh
# Just watch TypeScript:
npm run watch

# Or, watch TypeScript and run tests on change:
npm run tdd
```

## License

Apache 2.0

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