html - Angular 2+ 中的 NgStyle 不考虑输入参数中的 0(零)
问题描述
我有一个名为 top 和 bottom 的输入参数,正如他们所说,它是 CSS 中的 top 和 bottom。当我将组件 0 中的输入添加到顶部时,CSS 样式中不存在 0。例如顶部:0px 没有显示在那里。
<k-sidebar [id]="'testId'"
[attachToBody]="true"
[top]="0"
[bottom]="60"
[sideBarMode]="'sliding'"
[sideBarSide]="'right'"
[clickOutsideSidebar]="true"
[theme]="theme.dark"
[sideBarOverlap]="false"
[scrollable]="true"
[sideBarWidth]="'377px'"
[selfToggle]="true">
<!--<ng-template kennedysSidebar>
This is a template passed
</ng-template> -->
</k-sidebar>
而HTML组件的ngStyle是这样的。
[ngStyle]="{'width.px': sidebar.isDesktopWidth ? sideBarWidth : '',
'margin-bottom.px': marginBottom ? marginBottom : '',
'margin-top.px': marginTop ? marginTop : '',
'top.px': top ? top : '',
'bottom.px': bottom ? bottom : ''}"
底部我可以在 CSS 中看到它为 60px,但是,当我通过 0(零)时,它在 CSS 中不存在。任何想法为什么会发生这种情况?我猜 top(input) 被视为 null 什么的
解决方案
因为 0 是一个假值。条件top ? top : ''
将始终返回 false
推荐阅读
- javascript - UserInactivity 组件连续调用函数,而不是定时调用
- extjs - 如何正确添加过滤器和过滤数据?
- python - 如何为 Python 配置 arduino ide?
- python - 由 Param 定义的 Var 界限不会在 6.0.1 中更新
- html - 创建对类的多个数据目标和数据切换访问
- c# - 如何在我的实现 ILogger 中获取请求的唯一 ID(如来自 Serilog 的 requestid)?
- javascript - 如何避免 laravel 中的嵌套形式?
- c# - 不准确地报告重复的文件夹比较百分比,我的代码有什么问题?
- azure-cosmosdb - Cosmos DB - 分区合并
- node.js - 如何访问由 throw new Error() 方法创建的原始错误消息?