【发布时间】:2017-07-26 18:21:45
【问题描述】:
当鼠标悬停在 div 上时如何向 div 添加类。
模板 -
<div class="red">On hover add class ".yellow"</div>
组件 -
import {Component} from 'angular2/core';
@Component({
selector: 'hello-world',
templateUrl: 'src/hello_world.html',
styles: [`
.red {
background: red;
}
.yellow {
background: yellow;
}
`]
})
export class HelloWorld {
}
[注意-我特别想添加一个新类而不是修改现有类]
叹息!这是一个正常的用例,我还没有看到任何直接的解决方案!
【问题讨论】:
-
使用指令。阅读这篇文章,你应该能够弄清楚其余的 :) angular.io/docs/ts/latest/guide/attribute-directives.html
-
有什么理由不为此使用 CSS
:hover?