Answer the question
In order to leave comments, you need to log in
How to update a component from outside in React.js? Or how to bind React components and Angular directives?
I wrote an application in Angular 1.x The application is large and soon the brakes became noticeable, optimization partially improved the situation, but not enough. I want to transfer the heaviest things to React, I don’t want to completely rewrite the application to React (too large)
How to re-render (from the Angular directive) a React component when updating the scope?
Angular directive code:
class IstManagerListRowDirectiveClass extends IstDirectiveClass {
constructor() {
this.restrict = "E";
this.scope = false;
this.uid = null;
super.constructor();
}
unboundLink(scope, element, attr) {
/*this.watchCollection - обертка над scope.$watchCollection()*/
this.watchCollection("uid", (newUid, oldUid) => {
if(angular.isNumber(newUid) || angular.isString(newUid)){
this.uid = newUid;
const ReactElement = (<IstManagerListRowComponent managerUid = {this.uid}></IstManagerListRowComponent>);
ReactDOM.render(ReactElement, element[0]);
} else {
console.error("Класс: '"+this.constructor.name+"'; uid должен быть строкой или числом");
}
});
}
static createInstance() {
IstManagerListRowDirectiveClass.instance = new IstManagerListRowDirectiveClass();
return IstManagerListRowDirectiveClass.instance;
}
};
app.directive("istManagerListRow", IstManagerListRowDirectiveClass.createInstance);
class IstManagerListRowComponent extends React.Component{
constructor(data){
super.constructor(data);
this.state = {
managerUid: this.props.managerUid
};
}
render() {
return (<div className="table-row">this.state.managerUid </div>);
}
}
Answer the question
In order to leave comments, you need to log in
this.watchCollection
class IstManagerListRowComponent {
}
export default {
controller: IstManagerListRowComponent,
bindings: {
'uid': '='
},
template: `
<div className="table-row">$ctrl.uid </div>
`
}
class IstManagerListRowComponent {
set uid(value) {
this._uid = value;
// do something
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question