我有一些 react 组件,我想在 angular 6 应用程序中重用相同的组件。可以来一些建议我最好的方法来做到这一点。
最佳答案
可能有第三方助手用于此目的,但它们的行为方式相同,React 组件在需要时被渲染和卸载:
@ViewChild('container') containerRef: ElementRef;
ngOnInit() {
ReactDOM.render(<ReactComponent/>, this.containerRef.nativeElement);
}
ngOnDestroy() {
ReactDOM.unmountComponentAtNode(this.containerRef.nativeElement);
}
React 组件可以通过 props 与 Angular 组件交互。
关于angular - 如何在 Angular 6 应用程序中使用 React 组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55411994/