Is it possible to conditionally display element at

2019-01-13 21:15发布

This question already has an answer here:

I have some code that uses Polymer attributes on elements, for example:

<paper-drawer-panel force-narrow>

The way polymer works is that I can't simply say force-narrow="false" if I want to disable the attribute, it has to be removed altogether. Is there a way in Angular2 to conditionally remove the entire attribute? I can't seem to find any information on this topic. I could use ngIf and repeat the entire element with and without the attribute but I would rather not if possible. Thanks!

1条回答
叼着烟拽天下
2楼-- · 2019-01-13 21:53

Simple attribute binding does what you want:

[attr.force-narrow]="someField ? true : null" 

the attribute is not removed when someField is false, only when it's null

查看更多
登录 后发表回答