我有一个Angular列表,我期望在元素li被点击时,显示的外观和其他元素不一样。可以通过li被点击时,给该元素分配一个CSS样式的方式来实现。
定义一个selected CSS类:
list当前元素等于selectedHero的值时,施加.selected类:
这参照了官网上介绍的语法:
The Angular class binding makes it easy to add and remove a CSS class conditionally. Just add [class.some-css-class]=“some-condition” to the element you want to style.
要获取更多Jerry的原创文章,请关注公众号"汪子熙":