Тёмный
No video :(

@ViewChild in Angular | Data Binding | Angular 12+ 

procademy
Подписаться 54 тыс.
Просмотров 47 тыс.
50% 1

In this lecture, you are going to learn about @ViewChild decorator in angular. The @ViewChild decorator in angular is used to access an HTML element, a component or a directive in the component class.
Also remember that @ViewChild decorator returns the first matching element from the DOM and assign it to the property which we have decorated it with @ViewChild.
Let's understand @ViewChild decorator with an example.

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

 

27 авг 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 44   
@user-th5ec6zh3i
@user-th5ec6zh3i 10 месяцев назад
Thank you, Sir! You're one of the best teacher on RU-vid!
@Naldjei3396
@Naldjei3396 6 месяцев назад
Awesome how I watch your videos to learn one thing and at the end I learnt a lot more. You're a great teacher. Thank you!
@nuadoixaxunuadoixaxu2182
@nuadoixaxunuadoixaxu2182 2 года назад
Will you please explain the difference about the use of viewchild vs @input@output... what is the advantages and disadvances over the other.
@sourandbitter3062
@sourandbitter3062 Год назад
@ViewChild is to access child elements/components from the parent component. @Input or @Output are to access data bindings in the child component that were set inside the parent component's template.
@DD-vc7fq
@DD-vc7fq Год назад
@@sourandbitter3062 That answer does not seem satisfactory to be honest. I guess the main question is: Why would you ever use @Output and EventEmitter when passing data from child component to parent component, when @ViewChild seems way more practical and does the same thing?
@leninnani5222
@leninnani5222 2 года назад
Nice videos, thank you
@virajjoshi7569
@virajjoshi7569 2 года назад
@ViewChild static property can you also explain that? Thank You.
@datarsairaghav2053
@datarsairaghav2053 11 месяцев назад
Property 'dateOfBirth' has no initializer and is not definitely assigned in the constructor. 11 @ViewChild('dobInput') dateOfBirth: ElementRef; 28th video @ViewChild video
@maksat-mad
@maksat-mad Год назад
Very clear explanation, thank you!
@raviverma2431
@raviverma2431 Год назад
Thank you so much Its really very much helpful 🎉🎉
@stevecriddle
@stevecriddle Год назад
Why does sayHello() get called 4 times when the page displays?
@sivaprasad10410
@sivaprasad10410 2 года назад
in which scenario we can use @ViewChild decorator
@dimon.digital
@dimon.digital Год назад
Thank you very much! 👋
@user-hd8dm5ur3i
@user-hd8dm5ur3i 2 года назад
Maybe, I don't get something, but it looks like if person was born on 27-th of October, 2001, he is not 21 y.o. yet - how it is explained with this method 'calculateAge()' Just saying Btw - content is very g00d - THANKS!
@ashishkumarnath1259
@ashishkumarnath1259 Год назад
well the method only considers years , hence you get 2022-2001 = 21 years
@user-gz8ub3fl6r
@user-gz8ub3fl6r Год назад
I am getting this error when trying to access element. Ts: @ViewChild('', { static: false }) : ElementRef; But i am getting this error: Property '' has no initializer and is not definitely assigned in the constructor. Html: . Can you please help me on this?
@sourandbitter3062
@sourandbitter3062 Год назад
You probably need to add an exclamation mark after the property name . This is called the non-null assertion operator and tells TypeScript that the property will be set at runtime even though TypeScript cannot detect it at compile time: @ViewChild('', { static: false }) !: ElementRef; //
@yurapekach7550
@yurapekach7550 Год назад
Thank you so much!
@viniciusmachadorodrigues1724
instead of using viewchild static, we could use dependency injection right?
@gtsin
@gtsin Год назад
The second method you described in the video: "Accessing child component in the parent component using ViewChild decorator" is not working anymore.
@techie2903
@techie2903 Год назад
It works.
@BrisLS1
@BrisLS1 10 месяцев назад
You could be having difficulty compiling. Try - @ViewChild(DemoComponent, {static :true}) demoComp : DemoComponent = {} as DemoComponent;
@daniel49245
@daniel49245 Год назад
if you are getting error try this: @ViewChild("dobInput") dateOfBirth!: ElementRef; @ViewChild("ageInput") age!: ElementRef; and if you want more precise calculation of age: calculateAge(){ let birthDate = new Date(this.dateOfBirth.nativeElement.value); let currentDate = new Date(); let diffInMilliseconds = Math.abs(currentDate.getTime() - birthDate.getTime()); let diffInYears = diffInMilliseconds / (1000 * 60 * 60 * 24 * 365.25); this.age.nativeElement.value = Math.floor(diffInYears); }
@PriyasLifesyle
@PriyasLifesyle 11 месяцев назад
thanks this worked for me
@swathykrishna9122
@swathykrishna9122 Год назад
Why statement in sayHello(), logged twice in console?
@shinocs7901
@shinocs7901 Год назад
did you get answer for this?
@viniciusmachadorodrigues1724
@@shinocs7901 at least in react, it happens because its on development mode. In angular it may the the same reason.
@MultiWarrr
@MultiWarrr Год назад
How it worked without declaring var inside afterviewinit method?
@siddharthakundarapu9487
@siddharthakundarapu9487 Год назад
hi i have got error in ts file property @ViewChild(DemoComponent, {static: true}) demoComp: DemoComponent; ->demoComp
@datarsairaghav2053
@datarsairaghav2053 11 месяцев назад
Property 'age' has no initializer and is not definitely assigned in the constructor. 12 @ViewChild('ageInput') age: ElementRef; ~~~
@BrisLS1
@BrisLS1 10 месяцев назад
You can try - = {} as ElementRef; to get it to compile. I don't know why he does not have to initialize things. This may be a setting somewhere.
@ravishsingh1112
@ravishsingh1112 Год назад
please share link of java script course #procademy
@ahamed7794
@ahamed7794 2 года назад
Got error object is possibly undefined
@jayakumar2927
@jayakumar2927 2 года назад
share github code
@SrinathJog
@SrinathJog Год назад
here in your example if we delete even console giving error. It means not able to call function . Can you explain why it is like that ? what is the relation between and {{democomp.sayHello()}}
@techsharp257
@techsharp257 2 года назад
@ViewChild('dobInput') dateOfBirth: ElementRef; @ViewChild('ageInput') age: ElementRef; Error Property 'dateOfBirth' has no initializer and is not definitely assigned in the constructor. Property 'age' has no initializer and is not definitely assigned in the constructor. I am using Angular 14.
@benageandy8374
@benageandy8374 2 года назад
change @ViewChild('dobInput') dateOfBirth: ElementRef to @ViewChild('dobInput') dateOfBirth!: ElementRef @ViewChild('ageInput') age: ElementRef; to @ViewChild('ageInput') age!: ElementRef;
@deepesttrouble1
@deepesttrouble1 2 года назад
gotta add `!` like: dateOfBirth!
@ahamed7794
@ahamed7794 2 года назад
Got error : object is possibly undefined
@morishwilson7360
@morishwilson7360 Год назад
@ViewChild('dobInput') dateOfBirth!: ElementRef; Try "!" after "dateOfBirth" and before ":"
@vidhyaviswanath5441
@vidhyaviswanath5441 Год назад
Same for me😬
Далее
Whoa
01:00
Просмотров 31 млн
Ajdarlar...😅 QVZ 2024
00:39
Просмотров 377 тыс.
C’est qui le plus fort 😂
00:18
Просмотров 9 млн
Angular 18 is EXACTLY what we needed
9:15
Просмотров 74 тыс.
Data Binding & Rendering in LWC | EP-2
46:18
Просмотров 29 тыс.
Subjects in RxJS | Observables | Angular 12+
16:14
Просмотров 54 тыс.
Whoa
01:00
Просмотров 31 млн