Monday, April 3, 2017

Inputs for components in Angular 2.

Hand them in at a tag like so:

<selector-for-foo [my-something-er-other]="13"></selector-for-foo>

 
 

Inside the component itself you'll need an import statement like so:

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

 
 

Open up the component like this:

export default class Foo implements OnInit {
   @Input() mySomethingErOther: string;

 
 

Note that you may log this.mySomethingErOther to the console in OnInit but not in the constructor. Also note the difference between camel case and kebab case.

No comments:

Post a Comment