A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/angular-js/property-binding-in-angular-8/ below:

Property binding in angular 8

Property binding in angular 8

Last Updated : 11 Sep, 2020

Property Binding is a one-way data-binding technique. In property binding, we bind a property of a DOM element to a field which is a defined property in our component TypeScript code. Actually, Angular internally converts string interpolation into property binding.

In this, we bind the property of a defined element to an HTML DOM element.

Syntax:

<element [property]= 'typescript_property'>

Approach:

Example 1: setting value of an input element using property binding.

app.component.html

javascript
<input style = "color:green;
                margin-top: 40px; 
                margin-left: 100px;" 
[value]='title'>

app.component.ts

javascript
import { Component } from '@angular/core';    
@Component({    
  selector: 'app-root',    
  templateUrl: './app.component.html',    
  styleUrls: ['./app.component.css']    
})    
export class AppComponent {   
  title = 'GeeksforGeeks'; 
}   

Output:

Example 2: getting source of the image using property binding.

app.component.html

html

app.component.ts

javascript
import { Component } from '@angular/core';    
@Component({    
  selector: 'app-root',    
  templateUrl: './app.component.html',    
  styleUrls: ['./app.component.css']    
})    
export class AppComponent {   
  src = 'https://www.geeksforgeeks.org/wp-content/uploads/gfg_200X200-1.png'; 
}   

Output:

Example 3: disabling a button using property binding.

app.component.html

html
<button [disabled]='bool' style="margin-top: 20px;">GeekyButton</button>

app.component.ts

javascript
import { Component } from '@angular/core';    
@Component({    
  selector: 'app-root',    
  templateUrl: './app.component.html',    
  styleUrls: ['./app.component.css']    
})    
export class AppComponent {   
  bool = 'true'; 
}   

Output:



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4