Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Angular 2 have an 'equivalent' to componentDidMount in ReactJS

Tags:

angular

I'm able to apply some GSAPI effects to dynamically generated graphics by placing the required code in componentDidMount() in a React-based application.

I've tried using a Promise and placing the same code in the 'next' method, but it seem to execute "too early" so the GSAPI effects are not created.

Suggestions welcome:)

like image 679
Oswald Campesato Avatar asked Feb 22 '16 23:02

Oswald Campesato


People also ask

What is componentDidMount in React?

The componentDidMount() method is called after the component is rendered. This is where you run statements that requires that the component is already placed in the DOM.

When should I use componentDidMount and componentDidUpdate?

The componentDidUpdate()is called after componentDidMount() and can be useful to perform some action when the state of the component changes. Parameters: Following are the parameter used in this function: prevProps: Previous props passed to the component. prevState: Previous state of the component.

Can React component be used in Angular?

You are now ready to use the GoodData React Components in your Angular app. You can use wrapped components across your app. You can pass the component props to it and even update them using data-binding.

What is the difference between Reactjs and Angular?

React is a library, but Angular is a full-fledged framework. The virtual DOM and one-way data binding are used by React. js, but the real DOM and two-way data binding are used by Angular. There's also a speed difference (React's is faster) and a difference in bundle size (React's is smaller) (React works a bit faster).


Video Answer


1 Answers

@Oswald I think you are doing some manipulation of DOM after component is rendered so ngAfterContentInit seems to be appropriate for this case.

There are other lifecycle methods available as well. Have a look here: https://angular.io/docs/ts/latest/guide/lifecycle-hooks.html#!#hooks-overview

like image 107
Vikash Avatar answered Oct 18 '22 22:10

Vikash