【发布时间】:2017-05-08 14:17:47
【问题描述】:
当我在 w3schools.com Try It page 中测试 ng-class 时,一切正常,如文档所述。当我在一个简单的 Angular 2 应用程序中尝试它时,我没有得到任何乐趣。
这是我的步骤。在终端窗口中:
-
ng new classTest cd classTestng serve
在文本编辑器中:
app.component.css
.red {
color: #f00;
}
app.component.html
<h1 ng-class="{'red': true}">
{{title}}
</h1>
结果:文本 app works! 显示为黑色,而不是红色。我已经尝试了许多其他变体,例如 ng-class="'red'",在 w3schools.com 中 Try It page,文字随你喜欢变红。
我错过了什么?
【问题讨论】:
标签: angular angular-directive angular-template