Angular ngClass 条件类工作正常,但应用程序在构建时失败
当我使用哈巴狗代码单击某个选项卡时,我想添加一个“活动”类
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
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论