A clean React-like abstraction for rendering non-Angular components within an Angular app.
# Using Yarn:
yarn add ngcomponent
# Or, using NPM:
npm install ngcomponent --saveNote: This example is in TypeScript, but it works just as well in vanilla JavaScript
importNgComponentfrom'ngcomponent'interfaceProps{foo: numberbar: string[]}interfaceState{}constmyComponent={bindings: {foo: '<',bar: '<'},template: ` <div></div> `,controller: classextendsNgComponent<Props,State>{
...
}}importNgComponentfrom'ngcomponent'interfaceProps{data: number[]type: "bar"|"line"}interfaceState{chart: Chart}constchartJSWrapper={bindings: {data: '<',type: '<'},template: `<canvas></canvas>`,constructor(private$element: JQuery){}controller: classextendsNgComponent<Props,State>{componentDidMount(){this.state.chart=newChart($element.find('canvas'),{data: props.data,type: props.type})}render(){this.state.chart.data=this.props.datathis.state.chart.type=this.props.typethis.state.chart.update()}componentWillUnmount(){this.state.chart.destroy()}}}NgComponent has a React-like component lifecycle API:
render()(use this to react to changes tothis.props)componentWillMount()componentDidMount()componentWillReceiveProps(props)shouldComponentUpdate(props, state)componentWillUpdate(props, state)componentDidUpdate(props, state)componentWillUnmount()
npm test# Just watch TypeScript:
npm run watch
# Or, watch TypeScript and run tests on change:
npm run tddApache 2.0