I am currently working on a project where I need to pass some @input values based on component. So, that the directive will work accordingly. But the problem is I couldn't get reference of that directive. Instead I only got the elementRef in return. Please refer the below stackblitz sample for more reference.
Asked
Active
Viewed 2,246 times
1 Answers
5
There are to ways to fix it:
1) Using read
option:
@ViewChild("myCustomDir", { read: MyCustomDirective}) myCustomDir: MyCustomDirective;
See also:
2) Using exportAs
directive.ts
@Directive({
selector: "[myCustom]",
exportAs: 'myCustom'
^^^^^^^^^^^^^^^^^^^^
})
export class MyCustomDirective {
...
}
html
<h1 myCustom #myCustomDir="myCustom">
^^^^^^^^
See also:

yurzui
- 205,937
- 32
- 433
- 399
-
Thank you for the quick reply. It works. Thank you so much. – Arun Kumar Subburaj Jun 04 '18 at 13:15