Constructor | ngOninit |
A constructor is not the concept of Angular. It is the concept of JavaScript's class. | ngOninit is the second stage of Angular component lifecycle hook whenever is called when angular is done which creating the component. |
Constructor is best place to add all dependencies | ngOninit function which guarantees you that the component has already been created. |
Constructor is automatically called at the time of creating the object of the class. | Invoked by Angular when component is initialized |
Used for Injecting dependencies | Actual business logic performed |
we should use constructor() to setup Dependency Injection | is a better place to write "actual work code" that we need to execute as soon as the class is instantiated. |
Subscribe to:
Post Comments (Atom)
How to build an Express and Node.js app with Typescript
In this tutorial, you will learn how to set up a Node.js and Express project with Typescript and live auto-reloading. Note that this metho...
-
Boolean values are supported by both JavaScript and TypeScript and stored as true/false values. TypeScript Boolean: let isOn:boolean = t...
-
You can generate Splash Screens and Icons for your iOS, Android or Progressive Web Application using the @capacitor/assets tool. Step 1:...
-
Cross-Platform: TypeScript runs on any platform that JavaScript runs on. The TypeScript compiler can be ...
No comments:
Post a Comment