Only one structural directive can be applied

原文链接:Only one structural directive can be applied – 每天进步一点点 (longkui.site)

某天调试angular的时候,开始报这个错:

Only one structural directive can be applied

或者

Can’t have multiple template bindings on one element. Use only one attribute prefixed with *

翻译过来就是 “只能应用一个结构指令

看了一下我的代码

<div  *ngIf="type==0" *ngFor="let data of listOfData"     >

</div>

本意是想先通过if控制是否显示组件,再去渲染数据,结果angular直接报错,也就是说ngIf 和 ngFor 不能放在同一级使用。解决办法也很简单,外面再套一层就可以了。


          <div  *ngIf="1==0"      >
              <div *ngFor="let data of listOfData">

              </div>
          </div>

posted on   longkui  阅读(3)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示