Inputs in Angular 2

Inputs helps pass the data dynamically to the component. There are situations where you pass data to component and in turn component would invoke the service and fetch the desired result.Inputs are ideally suitable for such situation.

Defining Inputs in Component :

  1. @Input  directive in the Component which is imported from angular2/core.
  2. Defining Inputs in Component MetaData.

Example  of Inputs with directive:


import {Component,Input} from 'angular2/core'

@Component({

'selector':inputsample,

'template':"<span>{{Name}} </span>"

})

export class InputsampleComponent

{

@Input Name ;

}

Using  Input in Root/App Component :


<inputsample [Name ]="somename"> </inputsample>