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

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..
My Blogs - https://code-sample.com and https://code-sample.xyz
My Book1 - BEST SELLING ANGULAR BOOK (INCLUDING ALL VERSIONS 2, 4, 5, 6, 7)
My Book2 - ANGULAR 2 INTERVIEW QUESTIONS BOOK - Both Books are Available on WorldWide.

www.code-sample.com/. Powered by Blogger.
^