angularjs - Angular 1.4 应用程序中的 React 组件
问题描述
我有一个使用 gulp 构建的 Angular 应用程序。我想在其中使用 React 组件来实现不同的功能。Angular 应用程序通过脚本标签加载 js,React 应用程序有自己的存储容器等,并且正在使用 React 16。
如何在 angular.js 中导入我的组件等。
解决方案
您可以React Component
与 Angular 一起使用,也可以在Directive
内部使用它
$onInit
angular
var HelloWorld = React.createClass({
displayName:'Hello World',
render:function(){
return React.DOM.div(Test, "Hello, ",this.props.value1);
}
});
$scope.name = 'World!';
app.directive('hello', function(){
return {
restrict:'E',
scope:{
name:'='
},
link:function(scope, el, attrs){
scope.$watch('name', function(newValue, oldValue){
var MyComponent = React.createFactory(HelloWorld);
ReactDOM.render(
MyComponent({value1:newValue}),
el[0]
);
})
}
}
})
推荐阅读
- r - 您如何排除 r lm 中的交互项?
- python - 在 Python Paramiko 中捕获 AuthenticationException
- tensorflow - 为什么需要使用 tf.Variable?
- javascript - 反应 SPA。用于处理登录状态的全局状态存储 API?
- java - 随机只运行一个java方法
- javascript - 当错误消息不显示位置时查找错误
- android - 如何在 ViewPager 中构建嵌套片段?
- react-native - 错误 ITMS-90163:“无效的代码签名权利 - expo build
- python - 查找元音:重新编译模式不将单词的元音保持在一起
- asp.net - 当用户处于非活动状态时从 Asp.net Identity 自动注销