如何在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 {
}
[注意 - 我特別想添加一個新的類,而不是修改現有的類]
嘆息!這是一個正常的用例,我還沒有看到任何直接的解決方案!
用指令。閱讀這篇文章,你應該能夠找出其餘的:) https://angular.io/docs/ts/latest/guide/attribute-directives.html –
任何不使用CSS':hover'的理由這個? –