Angular ngClass 条件类工作正常,但应用程序在构建时失败

发布于 2025-01-17 07:44:18 字数 1052 浏览 2 评论 0原文

当我使用哈巴狗代码单击某个选项卡时,我想添加一个“活动”类

a.nav-link([class.active]="view === 'profile'", (click)="changeView('profile')") Profile
                
a.nav-link([class.active]="view === 'products'", (click)="changeView('products')") Products
                
a.nav-link([class.active]="view === 'loans'", (click)="changeView('loans')") Loans
                
a.nav-link([class.active]="view === 'notifications'", (click)="changeView('notifications')") Notifications

它工作正常,如图所示 输入图片此处描述

但是,当我为生产构建它时,我收到错误

此条件将始终返回“false”,因为类型“贷款”和“个人资料”没有重叠。< /code>

我用过typeof view 并在任何给定时间返回字符串。我不知道为什么错误指向 view 变量的值作为类型。

在 .ts 文件中,我将视图变量初始化为 view:string = 'profile'

我缺少什么?我已经阅读并重新阅读了 AngClass ngClass 上的文档以及这里的几篇文章在 stackoverflow 上无济于事。

I want to add an "active" class when I click on a certain tab using the pug code

a.nav-link([class.active]="view === 'profile'", (click)="changeView('profile')") Profile
                
a.nav-link([class.active]="view === 'products'", (click)="changeView('products')") Products
                
a.nav-link([class.active]="view === 'loans'", (click)="changeView('loans')") Loans
                
a.nav-link([class.active]="view === 'notifications'", (click)="changeView('notifications')") Notifications

It works fine as can be seen in the image
enter image description here

However when I build it for production, I get the error

This condition will always return 'false' since the types '"loans"' and '"profile"' have no overlap.

I have used typeof view and it returns string, at any given time. I am at a loss as to why the error is pointing at the values of the view variable as the type instead.

in the .ts file, I innitialzed the view variable as view:string = 'profile'

What I'm I missing? I have read and re-read the angular docs on ngClass as well as several posts here on stackoverflow to no avail.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文