我需要动态标记一个上传按钮。到目前为止,我的代码:
<style>
.file_upload_wrap.background_file:before {
content: {{label}}; /* of course does not work */
}
</style>
<div class="file_upload_wrap background_file imgFormButton">
<input type="file" class="file_upload" (change)="uploadFile($event, file)" name="file" id="file" [(ngModel)]="model.file"
#file="ngModel">
</div>
Run Code Online (Sandbox Code Playgroud)
如何动态设置内容?
您可以使用attrcss函数检索属性的值
https://developer.mozilla.org/zh-CN/docs/Web/CSS/attr
component.css
.file_upload_wrap.background_file:before {
content: attr(data-content);
}
Run Code Online (Sandbox Code Playgroud)
component.html
<div class="file_upload_wrap background_file imgFormButton" [attr.data-content]="label">
<input type="file" class="file_upload" (change)="uploadFile($event, file)" name="file" id="file" [(ngModel)]="model.file"
#file="ngModel">
</div>
Run Code Online (Sandbox Code Playgroud)
编辑:stackblitz显示示例 https://stackblitz.com/edit/angular-muysky?file=app%2Fapp.component.ts
| 归档时间: |
|
| 查看次数: |
359 次 |
| 最近记录: |