Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ngcomponent

Package Overview
Dependencies
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ngcomponent

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

  • 4.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
22K
decreased by-18.84%
Maintainers
2
Weekly downloads
 
Created
Source

NgComponent Build Status npm mit

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

Installation

# 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

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

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

npm test

Hacking On It

# Just watch TypeScript:
npm run watch

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

License

Apache 2.0

Keywords

FAQs

Package last updated on 18 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc