15

I have a "bootstrapModal" attribute directive that adds bootstrap attributes to the host element:

data-placement="top" data-toggle="modal" data-target="#DefaultModalWindow"

Is it possible to HostBinding to an attribute like this?

<htmltag ... bootstrapModal placement="left">

And in the directive have something like that:

 @HostBinding('attributes.data-placement') // <== this don't work
 @Input() placement:string='top';

So the result should be:

<htmltag ... data-placement="left" data-toggle="modal" data-target="#DefaultModalWindow">
3
  • do you want to bind it dynamically or statically? Commented Sep 2, 2016 at 6:51
  • That should work fine if but hard to tell what you are actually trying to accomplish whithout seeing more code. Commented Sep 2, 2016 at 6:51
  • @micronyks better dynamically. Commented Sep 2, 2016 at 7:35

1 Answer 1

38

This should work:

@HostBinding('attr.data-placement')

Plunker

See also

Sign up to request clarification or add additional context in comments.

2 Comments

It works. Where can I find documentation about these properties? attr? and others
angular.io There aren't many. class, attr, style, style.xxx.px, style.xxx.% (and probably all other valid units). Did I miss some?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.