pass parameter through selectors in component Angular 2

amansoni211 picture amansoni211 · Dec 8, 2016 · Viewed 7.7k times · Source

I actually want to apply a specific class on button (which is in btn.component.html) if it is passed through the selector.

my selector is

<btn></btn>

btn.component.ts is

import {Component} from '@angular/core';

@Component({
  selector: 'btn',
  template: require('./btn.component.html')
})

export class BtnComponent { }

btn.component.html is

<button>Okay</button>

Answer

ranakrunal9 picture ranakrunal9 · Dec 8, 2016

You can pass class name as params like :

<btn className="btn-class"></btn>

//Component

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

@Component({
  selector: 'btn',
  template: `<button [class]="className">Okay</button>`
})    
export class BtnComponent {
  @Input() className :string = '';
}