javascript - Access directive function from component class or template -


i've got component needs call function in mydirective can't figure out how gain access it, keeps spewing out errors no matter try.

i looked @ view child in docs didn't work me, don't show template usage can't sure if i'm doing right.

edit:

i think it's important note directive imports component, importing directive component seems give circular reference, causing mydirective become undefined if try inject directives:[] part of @component decorator.

what need this:

component:

import {mydirective} 'my-directive.directive';  // shortened example's sake @component({   directives: [mydirective] })  export class {   @viewchild(mydirective) mydir: mydirective; } 

component template:

<button (click)="mydir.mydirectivefunc()"></button> 

what don't want declare mydirective on button because add undesired behavior. want gain access functions.

how can this?


Comments

Popular posts from this blog

php - Auto increment employee ID -

python - Evaluating the next line in a For Loop while in the current iteration -