Тёмный
No video :(

Angular component lifecycle hooks 

kudvenkat
Подписаться 832 тыс.
Просмотров 218 тыс.
50% 1

Text version of the video
csharp-video-tu...
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our RU-vid channel. Hope you can help.
/ @aarvikitchen5572
Slides
csharp-video-tu...
Angular 2 Tutorial playlist
• Angular 2 tutorial for...
Angular 2 Text articles and slides
csharp-video-tu...
All Dot Net and SQL Server Tutorials in English
www.youtube.co...
All Dot Net and SQL Server Tutorials in Arabic
/ kudvenkatarabic
In this video we will discuss Angular component lifecycle hooks.
A component has a lifecycle managed by Angular. Angular
1. Creates the component
2. Renders the component
3. Creates and renders the component children
4. Checks when the component data-bound properties change, and
5. Destroys the component before removing it from the DOM
To tap into and react when these life cycle events occur, angular offers several lifecycle hooks
The 3 most commonly used hooks are
ngOnChanges - Executes, every time the value of an input property changes. The hook method receives a SimpleChanges object containing current and previous property values. This is called before ngOnInit.
ngOnInit - Executes after the constructor and after ngOnChange hook for the first time. It is most commonly used for component initialisation and retrieving data from a database.
ngOnDestroy - Executes just before angular destroys the component and generally used for performing cleanup.
There are 3 simple steps to use the Life Cycle Hooks
Step 1 : Import the Life Cycle Hook interface. For example, to use ngOnInit() life cycle hook, import OnInit interface.
import { OnInit } from '@angular/core';
Step 2 : Make the component class implement the Life Cycle Hook interface, using the implements keyword as shown below. This step is optional, but good to have so you will get editor support and flags errors at compile time if you incorrectly implement the interface method or make any typographical errors.
export class SimpleComponent implements OnInit { }
Step 3 : Write the implementation code for the life cycle interface method. Each interface has a single hook method whose name is the interface name prefixed with ng.
ngOnInit() {
console.log('OnInit Life Cycle Hook');
}
Let's understand ngOnChanges life cycle hook with a simple example. Here is what we want to do. As soon as the user starts typing into the text box, we want to capture the current and previous value and log it to the browser console. We can very easily achieve this by using the ngOnChanges life cycle hook.
ngOnChanges, is called every time the value of an input property of a component changes. So first let's create a SimpleComponent with an input property as shown below. We will continue with the example we worked with in our previous video. Add a new folder in the App folder and name it Others. Add a new TypeScript file to this folder and name it - simple.component.ts. Copy and paste the following code which is commented and self explanatory.
// Step 1 : Import OnChanges and SimpleChanges
import { Component, Input, OnChanges, SimpleChanges } from '@angular/core';
// The selector "simple" will be used as the directive
// where we want to use this component. Notice we are
// also using the simpleInput property with interpolation
// to display the value it receives from the parent
// component
@Component({
selector: 'simple',
template: `You entered : {{simpleInput}}`
})
// Step 2 : Implement OnChanges Life Cycle Hook interface
export class SimpleComponent implements OnChanges {
// Input property. As and when this property changes
// ngOnChanges life cycle hook method is called
@Input() simpleInput: string;
// Step 3 : Implementation for the hook method
// This code logs the current and previous value
// to the console.
ngOnChanges(changes: SimpleChanges) {
for (let propertyName in changes) {
let change = changes[propertyName];
let current = JSON.stringify(change.currentValue);
let previous = JSON.stringify(change.previousValue);
console.log(propertyName + ': currentValue = '
+ current + ', previousValue = ' + previous);
// The above line can be rewritten using
// placeholder syntax as shown below
// console.log(`${propertyName}: currentValue
// = ${current }, previousValue = ${previous }`);
}
}
}

Опубликовано:

 

27 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 44   
@edmilinski1295
@edmilinski1295 6 лет назад
Incredible, how well you do this. best teaching style, attitude, etc I've seen. cheers
@arunmohanmc
@arunmohanmc 5 лет назад
I know angular Js earlier, Within 3 hours of time, your videos gave all required info to know how, when, which, what, why, where etc.. Very helpful. Thank you so much for your time and efforts.
@Csharp-video-tutorialsBlogspot
Hello Arun - Thank you very much for taking time to give feedback. This means a lot. I am very glad you found this AngularJS course useful.
@insofcury
@insofcury 5 лет назад
Thank you for explaining everything in detail, love your methodology
@OnBurak1
@OnBurak1 3 года назад
Your way of talking is very clear I can even easily follow what you say with 2x speed. Wish you had React and Node tutorials too.
@irinamitrea6013
@irinamitrea6013 6 лет назад
you're the best teacher i know. thank you a lot!
@priyankaravichandran851
@priyankaravichandran851 3 года назад
No one will explain this much clear as u
@kamdemkakengne
@kamdemkakengne 4 года назад
Thank you very much Venkat! You are a great teacher!
@jayeshmali299
@jayeshmali299 5 лет назад
Really helpful sir, last weekend interviewer from big mnc company asked me this simple question and i couldn't explain it well .It will be really helpful if you can explain in detail about all life cycle hooks method.
@drasian115
@drasian115 5 лет назад
Sir please make videos on simple small projects in angular. It'll be a big help for students like us. Love your teaching ❤️
@Csharp-video-tutorialsBlogspot
Hello Rimpa We create a simple angular project in the following Angular CRUD tutorial. This tutorial uses Angular 5 and covers all the concepts we were not able to cover in Angular 2 tutorial. ru-vid.com/group/PL6n9fhu94yhXwcl3a6rIfAI7QmGYIkfK5 Even in the following course we build a small anular project from scratch using Angular 6. In this course we have covered important advanced angular concepts we were not able to cover in Angular 2 and Angular 5 playlists. ru-vid.com/group/PL6n9fhu94yhWNJaDgh0mfae_9xoQ4E_Zj The following video explains the difference between angular versions. ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-bAx2LgQLkl8.html
@321zipzapzoom
@321zipzapzoom 5 лет назад
What a great teaching Style you have got Sir..kudos
@lamarlayne
@lamarlayne 7 лет назад
That was awesome! Very clear and concise. Thanks!
@RethinkingUI
@RethinkingUI 6 лет назад
Excellent Videos Thank you very much Sir.
@ashok2484
@ashok2484 5 лет назад
thnk u sir...this lesson is very useful for me....
@vikassharma2191
@vikassharma2191 7 лет назад
A big fan of you sir.
@kavyas1910
@kavyas1910 6 лет назад
can u suggest some simple project videos so that i would develop it manually.. i am really a big fan of u..thank u for your clear explaination
@cgprodigy6189
@cgprodigy6189 6 лет назад
You the best big time. Keep up the good work
@Lalitha_Krishnamurthy
@Lalitha_Krishnamurthy 6 лет назад
Your vedios are really best of better
@Venkatakrishna.bvk2
@Venkatakrishna.bvk2 7 лет назад
@Kudvenkat ur videos are really awesome . Please upload more videos.
@playwith_code
@playwith_code 5 лет назад
Really its a helpfull. Thanks
@uday1002305
@uday1002305 5 лет назад
Hi Sir, can you please explain it in detail with example. Only ngonchane ngoninit ngondestroy understand. But not understand ngDoCheck and its parts. So request you to explain in detail with example
@myvinbarboza3038
@myvinbarboza3038 4 года назад
This is why I was here...
@ystavrou5870
@ystavrou5870 4 года назад
Very well explained
@kiranbabuetukiri2859
@kiranbabuetukiri2859 6 лет назад
Your videos are awesome. Is there any videos, component are adding dynamically to another dynamically added component. .
@Csharp-video-tutorialsBlogspot
Hi Kiran. Not in this playlist. We will cover this concept in our upcoming videos in Angular CRUD tutorial. Here is the link to that playlist. Please stay tuned. ru-vid.com/group/PL6n9fhu94yhXwcl3a6rIfAI7QmGYIkfK5
@uday1002305
@uday1002305 5 лет назад
@@Csharp-video-tutorialsBlogspot Hi Venkat, I checked and this concept is not in Crud. Also please let us know life cycle in detail with example
@vissumumbai
@vissumumbai 7 лет назад
Hi Venkat, I Followed all of the tutorials ex: WebAPI, Angular js, bootstrap that you are briefing with PPT's and Videos in you tube. Your explanation is awesome really no words to say for your great effort and hard work. I have a quick question in Angular 2. I saw employe.component.js and employe.component.js.map files for each component that you are creating employe.component.ts. Can you please brief me why these two additional files are creating what is the main purpose.
@RachitJain4U
@RachitJain4U 5 лет назад
Awesome :) Thanks :)
@raqibul1000
@raqibul1000 7 лет назад
Thanks a Billions.
@jnnirmal47
@jnnirmal47 6 лет назад
The last screenshot added seems wrong it shows screenshot of oninit() method whereas the video is for onChanges()
@nihaalg401
@nihaalg401 7 лет назад
great...😊
@DecentProgrammer
@DecentProgrammer 3 года назад
nice one
@m.e858
@m.e858 6 лет назад
things r not clear inside the ngOnChanges ?! for loop iterates through what ? well it's not clear to me what's inside ngOnChanges
@piyushpandey433
@piyushpandey433 6 лет назад
Thanks for explanation. What if multiple inputs are are collected? how onChange( ) work with multiple values get changed or a form changes ?
@vjayjaina
@vjayjaina 6 лет назад
OnChanges() by default outputs all the properties that are being updated. We can loop and display only the ones we want to.
@aniketbharalla3299
@aniketbharalla3299 5 лет назад
you have not inform that to use ngModule we should import FormsModule
@dileepkumarkaranki
@dileepkumarkaranki 3 года назад
At the end you are showing onInit life cycle hook slides
@solethio7928
@solethio7928 5 лет назад
thanks
@danielstephen4300
@danielstephen4300 5 лет назад
I am getting this error. i dont know where i went wrong. please help on this,.. Error: Template parse errors: Can't bind to 'ngModel' since it isn't a known property of 'input'. ("][(ngModel)]='usertext'/>
@dp7939
@dp7939 5 лет назад
make sure you have imported FormsModule into app.module.ts
@disha9876
@disha9876 5 лет назад
Also Please import ---> FormsModule in appModule.ts import { FormsModule } from '@angular/forms';
@thejourney8271
@thejourney8271 5 лет назад
Please name this tutorial as OnChanges Hook, It's not all LifeCycle Hooks..
@ashishsahare2548
@ashishsahare2548 4 года назад
if title of the video is lifecycle hooks then you must explain all the methods not only one.
Далее
Angular services tutorial
13:52
Просмотров 170 тыс.
ПОЁМ НАРОДНЫЕ ПЕСНИ🪗
2:04:11
Просмотров 1,1 млн
Angular component output properties
16:56
Просмотров 154 тыс.
Why dependency injection
11:53
Просмотров 156 тыс.
Angular vs React: which should you choose?
6:26
Просмотров 111 тыс.
Angular Injector
15:06
Просмотров 63 тыс.
Senior Angular Developer Interview (theory)
41:57
Просмотров 17 тыс.
Angular 2 routing tutorial
17:38
Просмотров 129 тыс.
Angular ngFor directive
9:10
Просмотров 147 тыс.