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

Angular中Mat-Icon组件无法正常显示,请求技术协助

Angular Mat-Icon 无法显示的解决方案

问题分析

从你提供的代码来看,核心问题出在字体链接的格式错误,导致Material Icons字体无法正常加载,最终图标显示为方框(即你提到的异常效果)。

具体修复步骤

1. 修正index.html中的字体链接空格错误

你的index.html里,Roboto字体的链接存在无效空格,这会导致浏览器无法正确请求字体资源:
原代码:

<link href="https://fonts.googleapis.com/css2? family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">

修改为(去掉?和family之间的空格):

<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">

同时确认Material Icons的链接格式正确(你的代码里这部分是对的):

<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

2. 验证图标名称正确性

你使用的keyboard_arrow_down是Material Icons的有效图标名称,这部分无需修改。

3. 检查依赖安装状态

确保已正确安装Angular Material依赖:

npm install @angular/material @angular/cdk

4. 清除缓存并重启项目

  • 清除浏览器缓存(快捷键:Ctrl+Shift+R 或 Cmd+Shift+R)
  • 停止当前的Angular服务,重新执行ng serve启动项目

内容的提问来源于stack exchange,提问作者Vinícius Kock

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 01:45:36