0
我想根據視頻教程使用簡單的指令。我不知道爲什麼,我的代碼不會影響文本顏色。有人能幫助我嗎?這裏是代碼:Angular2指令不工作
app.component.html:
<p colorer>textTMP</p>
app.component.ts:
import { Colorer } from './colorer.service';
@Component({
selector: 'app-component',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
providers: [ Colorer],
})
export class AppComponent{}
colorer.service.ts:
import { Input, Directive, HostListener, ElementRef } from '@angular/core';
@Directive({
selector: '[colorer]',
host: {
'(mouseenter)': 'color()'
}
})
export class Colorer {
constructor(private _el: ElementRef) {}
color() {
this._el.nativeElement.style.color = 'red';
}
}