Property binding

Property binding

As you can understand with the name property binding is used to bind the properties like [hidden] ="true". If we want to hide <div> or html tag than we use property binding.

Let us try to hide and show a paragraph. That we use commonly in the web development .

Define variable in the component eg show = true. Then come into your html file. Give property to the p tag. eg <p [hidden]="show"> this is property binding </p>

You will see that you will able to see the p tag with content. Now change show = false. It will hide p tag. This is how property binding used. For more information follow the link : https://angular.io/guide/template-syntax

How to add class dynamic from component to view.

We can use class.className [class.special]. in your component write

<div class="special" [class.special]="!isSpecial">This one is not so special.</div>

In the component file define a variable isSpecial =true. When isSpecial =true; then special class will add in the div isSpecial = flase then not.

要查看或添加评论,请登录

Sanjeev Kumar的更多文章

社区洞察

其他会员也浏览了