0

I have a DraggableDropZone directive which handles items being dropped on to it. I would like to set this directive on my component based on a boolean flag. Basically sometimes the component needs to be a drop target and sometimes it does not. Attribute binding does not seem to work.

Doesn't work:

<div [attr.DraggableDropZone]="DropZone"></div>

If I simply do this it works, so I know my directive is good:

<div DraggableDropZone></div>

So I need 'DraggableDropZone' to be added conditionally at runtime.

  • Update: It looks like this is just not supported: [link](http://stackoverflow.com/questions/37148080/use-angular2-directive-in-host-of-another-directive) – user2055119 Sep 30 '16 at 15:22

1 Answers1

0

You could use an input parameter and then control the behaviour in your DraggableDropZone directive:

<div [DraggableDropZone]="enabled"></div>

and

@Input('DraggableDropZone') enabled: boolean;
Lucas Tétreault
  • 953
  • 5
  • 15
  • I had tried that before but didn't think it was supported. I am getting: Template parse errors: Can't bind to 'DraggableDropZone' since it isn't a known property of 'div' – user2055119 Sep 30 '16 at 15:15