【发布时间】:2019-01-24 21:21:23
【问题描述】:
场景如下,我有一个上传文件的组件,但是看起来真的很丑(经典input type="file"),所以我想做一个风格化的标签(可能是图片什么的),当你点击它时获得与单击文件输入相同的行为。
我设法通过将我的upload.component 的模板放在我想要使用的模板中来完成这项工作,但由于我需要在许多不同的地方上传文件,我不想每次都重复代码。
这很好用..
.image-upload > input
{
display: none;
}
<div class="image-upload">
<label for="file-input">
<img src="placeholder.jpg"/>
</label>
<input id="file-input" type="file"/>
</div>
这不是..
<!-- my-other.component.html -->
<label for="file-input">
<img src="placeholder.jpg"/>
</label>
<app-upload></app-upload>
<!-- upload.component.html -->
<input id="file-input" type="file" />
那么有没有办法引用一个“封闭”在组件内的输入?
【问题讨论】:
标签: html css angular angular-components