You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS Code中Prettier格式化Angular HTML时printWidth失效问题

Angular开发中VS Code里Prettier格式化HTML异常问题

我在Angular开发时遇到了Prettier格式化HTML代码的异常:

  • VS Code全局设置里printWidth设为250
  • 项目根目录已添加.prettierrc.json,配置了"printWidth":100
  • 未勾选VS Code中Prettier的Single Attribute Per Line选项

但Prettier仍会把元素的每个属性单独换行,部分短属性则分成两行显示,看起来像是默认启用了80字符的printWidth。

异常格式化示例1(多属性元素):

<button
  pButton
  class="btn"
  type="button"
  label="Add Item(s)"
  (click)="handleClick()"
></button>

异常格式化示例2(短属性元素):

<div class="p-col-2" style="float: left">
  {{ "modules.user.orderdisplay.quantity" | translate }}
</div>

我已经搜索并尝试了多种解决方案,都没能解决这个问题,希望有人能帮忙排查原因。

内容的提问来源于stack exchange,提问作者MansouriAla

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 10:11:34