Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pass parameter through selectors in component Angular 2

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>
like image 393
amansoni211 Avatar asked May 09 '26 12:05

amansoni211


1 Answers

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 = '';
}
like image 145
ranakrunal9 Avatar answered May 12 '26 09:05

ranakrunal9



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!