Welcome Guest! (App Version 3.1)

websitnero logo name

Property Binding

Property Binding in Angular

Property Bidning uses the square-brackets to update the property in an HTML-Element based on the expression written infront of it.

Practical Example of "Property Binding"

Please follow the mentioned steps:

  1. Create a compennt named 'home'
  2. Add the home component in the app.component.html file removing all boilerplate code there.
  3. We will use source url of an image and a disabled boolean variable to show how property binding can be achieved in 3 ways.

home.component.html

<img src="./../../../assets/img/hermione.png" />

<hr/>

<img src="{{sourceLink}}" />
<img bind-src="sourceLink" />
<img [src]="sourceLink" />

<hr/>

<input type="text" disabled />

<hr/>

<input type="text" disabled="{{isDisabled}}" />
<input type="text" bind-disabled="isDisabled" />
<input type="text" [disabled]="isDisabled" />

home.component.ts

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {

  sourceLink: string = "./../../../assets/img/hermione.png";
  isDisabled = true;

  constructor() { }

  ngOnInit() {
  }

}

home.component.css

img {width:100px;}
  1. You'll get the following result.

Setting 'isDisabled' variable to false, renders:

WebsiteNero is highly optimized for learning various website developing technlogies. We try our best to add maximum modules and examples to help learn the concepts clearly and vividly. We try to present all content and examples as simple as we can removing any complexity to hurdle easy understanding. We try best provide you with worthful content, but we cannot guarantee full correctness of all the content on this site. While using this website, you agree to have read and accepted all our terms of use and conditions, cookie, and privacy policy. Copyright, 2013-2018 by websitenero.com. All Rights Reserved.