Actions of Event Binding

Angular 4 Property Binding and Examples

What Is Property Binding?
Property binding allows you to define an element attribute values from the component and its one-way data binding and also you can only set the data from the component to the view.

Example As – Parent Component class Is -
import { Component, Input } from '@angular/core';

@Component({
  selector: 'parent-Component',
  template: 'Its Comes from parent: {{InputTextUser}}'
})
export class ParentComponent {
  @Input() InputTextUser;
}


And The Child Component Class Is -
import { Component } from '@angular/core';

@Component({
  moduleId: module.UserId,
  selector: 'child-Component',
  template: `
      <parent-Component [InputTextUser]="txtUser"></parent-Component>
      <span [InputTextUser]="txtUser"></span>
  `
})
export class ChildComponent {
  txtUser = 'Anil';
}


In the parent component class, you need to indicate that it receives from the “InputTextUser” property and we do not need to do anything else for the span.

That means, whenever you the “txtUser” property changes on the child component class Angular will automatically update the property “InputTextUser” on parent component and span also.

Example 2 for Property Binding –
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-databind',
  templateUrl: `<img src="{{imgAngular_Logo}}" height="100"/><br/>
    <img [src]="imgAngular_Logo" height="100" /><br/>
    <img bind-src="imgAngular_Logo" height="100" />
  `
})
export class DatabindComponent implements OnInit {
  constructor() { }

  //ngOnInit method call
  ngOnInit() {
    let imgAngular_Logo = 'https://angular.io/assets/images/logos/angular/angular.svg';
  }
}


Stayed Informed - Angular Events Binding

I hope you are enjoying with this post! Please share with you friends. Thank you!!
ANIL SINGH

Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - https://code-sample.com and https://code-sample.xyz
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
Post a Comment
www.code-sample.com/. Powered by Blogger.
ASK Questions