How to add parameter to Angular HTML element seletror directive?

24 Views Asked by At

I have a simple directive which selector is an img.

@Directive(
  { selector: 'img' } 
)
export class ImageDirective {
...
}

How can I add boolean parameter to this directive? I tried it with

@Input() enabled: boolean = false;

html part:

<img [enabled]="true"

but it does not work, does'nt matter what I set, the this.enabled remains false;

Thanks

1

There are 1 best solutions below

0
user22760463 On

you should change your code: in the directive change your selector:

selector:'[img]'

in the html change to

<p [enable] = true ></p>

Follow the explanation on directive