
Ramiro Mendoza Alvarez
PreguntaSi quisiera que mi directiva pudiera recibir parámetros, como podría hacerlo?

Kevin Rafael Santacruz Burgos
Hola en el html quedaría así
<h3 appHighlight [bgColor]="'red'"> {{ product.title }} </h3>
Por otro lado, en la directiva la asignación no se puede hacer en el constructor ya que hasta ese punto no tiene asignado el valor del color.
import { Directive, ElementRef, Input, OnInit } from '@angular/core'; @Directive({ selector: '[appHighlight]' }) export class HighlightDirective implements OnInit { @Input() public bgColor: string; constructor( private element: ElementRef ) { } ngOnInit() { this.element.nativeElement.style.backgroundColor = this.bgColor; } }

Fernando Veloz Cleto
Agregando un Input a tu directiva, ej:
En la directiva
@Input() backgroundColor: string;
En el template:
<h3 appHighLight [backgroundColor]="'white'">Hola</h3>