Тёмный
No video :(

Property binding in Angular 2 

kudvenkat
Подписаться 832 тыс.
Просмотров 204 тыс.
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 Property binding in Angular with examples.
In Part 8, we discussed we can use interpolation to bind component class properties to view template. Another option to achieve exactly the same thing is by using Property binding.
In our previous video we have bound imagePath property of the component class to [img] element src property using interpolation as shown below.
[img src='{{imagePath}}'/]
We can rerwrite the above example, using property binding as shown below. Notice the [img] element src property is in a pair of square brackets, and the component class property is in quotes.
[img [src]='imagePath'/]
Both Interpolation and Property binding flows a value in one direction, i.e from a component's data property into a target element property.
What is the difference between Interpolation and Property binding
Interpolation is a special syntax that Angular converts into a property binding.
Interpolation is just a convenient alternative to property binding.
In some cases like when we need to concatenate strings we have to use interpolation instead of property binding as shown in the example below.
[img src='www.pragimtech....{{imagePath}}' /]
When setting an element property to a non-string data value, you must use property binding. In the following example, we are disabling a button by binding to the boolean property isDisabled.
[button [disabled]='isDisabled']Click me[/button]
If we use interpolation instead of property binding, the button is always disabled irrespective of isDisabled class property value
[button disabled='{{isDisabled}}']Click me[/button]
Some important points to keep in mind when using Property binding
Remember to enclose the property name with a pair of square brackets. If you omit the brackets, Angular treats the string as a constant and initializes the target property with that string.
[span [innerHTML]='pageHeader'][/span]
With Property binding we enclose the element property name in square brackets
[button [disabled]='isDisabled']Click me[/button]
We can also use the alternate syntax with bind- prefix. This is known as canonical form
[button bind-disabled='isDisabled']Click me[/button]
From security standpoint, Angular data binding sanitizes malicious content before displaying it on the browser. Both interpolation and property binding protects us from malicious content.
In the example below we are using interpolation. Notice the malicious usage of [script] tag.
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: '[div]{{badHtml}}[/div]'
})
export class AppComponent {
badHtml: string = 'Hello [script]alert("Hacked");[/script] World';
}
Angular interpolation sanitizes the malicious content and displays the following in the browser
Hello [script]alert("Hacked");[/script] World
In this example below we are using property binding.
'[div [innerHtml]="badHtml"][/div]'
Property binding sanitizes the malicious content slightly differently and we get the following output, but the important point to keep in mind is both the techniques protect us from malicious content and render the content harmlessly.
Hello alert("Hacked"); World

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

 

26 авг 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 36   
@adminssmoil6211
@adminssmoil6211 5 лет назад
Author, Your courses are very interesting and you are the best teacher! thank you !
@GistTech
@GistTech 7 лет назад
your a really great teacher and patient I love your videos
@mdwazid4806
@mdwazid4806 6 лет назад
Hi Sir, really its a very very good video clip for angula2 b`coz your way of teaching and English pronunciation is very good please provide this type video sir. I searched lots video not like that thank You sir
@V1kToo
@V1kToo 5 лет назад
brilliantly explained
@bigdogsmallman
@bigdogsmallman 7 лет назад
Thank you very Much. When I have my laptop I shall try it out :D
@anu1708
@anu1708 2 года назад
Sir as in my-app The sentence Loading AppComponent content here.. Can we set timing like till what time it should display.
@faizankhan-eq7ev
@faizankhan-eq7ev 6 лет назад
Using square brackets [propertyName], you are setting property of that HTML tag, using interpolation simply on an attribute, attribute={{value}}, you are setting value of an attribute of that tag , not the property , most of the attributes have equivalent property name but some don't
@AdebayoAdegbemboAsa
@AdebayoAdegbemboAsa 5 лет назад
Thank you so so much!!!
@premkagrani154
@premkagrani154 6 лет назад
Hello Sir, Can you please explain the point of Sanitizing the content which you have demonstrated in the end in this video. I googled Sanitized but was unable to understand the real meaning of it in angular. Any help will be appreciated. Thanks
@MrWiseCommentator
@MrWiseCommentator 6 лет назад
You can find more information on angular official documentation. angular.io/guide/security
@shaiksaidavali7279
@shaiksaidavali7279 6 лет назад
What is it about "innerHtml" property .was it work only in angular JS or without any JS like
@RachitJain4U
@RachitJain4U 5 лет назад
Awesome :) Thanks :)
@raqibul1000
@raqibul1000 7 лет назад
Thanks a Billions.
@johnny_rain3226
@johnny_rain3226 7 лет назад
Thank you
@pradeeshbm5558
@pradeeshbm5558 7 лет назад
Need some more explanation for interpolation and property binding. I really didn't understand the main difference (When to use).
@naodagere8210
@naodagere8210 4 года назад
Thank you Sir
@varunbabu008
@varunbabu008 7 лет назад
@Kudvenkat Lengend !
@choudharyrahul722
@choudharyrahul722 6 лет назад
is getting rendered as .. The innerHtml is not getting rendered.
@harshshrivastava2620
@harshshrivastava2620 5 лет назад
change the spelling to [innerHtml] ...:)..hope it works..its working fine for me.
@nandhinikumar4933
@nandhinikumar4933 6 лет назад
good tutorial
@vishakhatomar8416
@vishakhatomar8416 7 лет назад
i am getting this error for both span and div . "Can't bind to 'innerhtml' since it isn't a known property of 'div'." Due to this page is not loading.
@srinivasrapaka4729
@srinivasrapaka4729 7 лет назад
write innerHtml not innerhtml
@semikolon4229
@semikolon4229 7 лет назад
thanks, man
@taherhendawi8874
@taherhendawi8874 7 лет назад
Great job thnx a lot ! i didnt understand the last point.. i have not noticed any sanitize !!??
@Devilsnightforlife
@Devilsnightforlife 7 лет назад
He created a string which contained javascript tags with an alert method. If he just displayed the string in html, like if he didn't bind the string but just wrote it in the html, then the browser would interpret that there was a script in the string and would then attempt to run it, displaying an alert with the word "hacked". This could lead to cross-site scripting attacks. However, because both interpolation and property binding sanitizes the string, it ensures that the html won't read the malicious script in the string as javascript but instead interpret the whole thing as html. The property binding removes potentially dangerous tags, such as the tags, and interpolation escapes the string while keeping all of its content intact.
@taherhendawi8874
@taherhendawi8874 7 лет назад
Thor Klauson thnx a lot :)
@johannjust4723
@johannjust4723 6 лет назад
nice job =)
@RachitJain4U
@RachitJain4U 7 лет назад
Thank You Sir :)
@NKSazzie
@NKSazzie 6 лет назад
Hii, I tried this ( isDisabled = false; ) without defining the type of isDisabled as boolean in app.component.ts. But still this is rendering fine . I can't get why this behaviour is happening. It would be great if you include a tutorial specific to typescript.
@nageshsrinivas8045
@nageshsrinivas8045 6 лет назад
since typescript compiles to java script even java script code is also treated as valid typescript.hence when you assign the value false to isDisabled it becomes a boolean as per java script rules.This scould be a reason why its working fine.
@puttaarunkumar919
@puttaarunkumar919 6 лет назад
At instant 5:46 their should not be quotes when you are using interpolation.
@AdvikaSamantaray
@AdvikaSamantaray 6 лет назад
I thought the same. Then i tried by removing quotes and it still didn't work, where as property binding worked correctly. So I guess the point is right.
@vignesh739
@vignesh739 3 года назад
என்னா மனுசன்யா🙏🙏🙏
@WakefieldSeldon
@WakefieldSeldon 7 лет назад
Typescript and Angular seem so meaningless to me. With ES6 and ES7 you can do the same things cleaner and faster.
@utkarshraj3822
@utkarshraj3822 5 лет назад
That why Angular is not for you