Just delving into Angular 2 and encountering a minor hiccup.
Here's a quick custom directive designed to turn text green. However, there seems to be an issue with accessing the "defaultColor" string within ngOnInit - it keeps returning as "undefined" in the console log.
Any insights on what might be causing this?
Cheers!
import {Directive, ElementRef, OnInit} from 'angular2/core';
@Directive({
selector: '[myHighlight]'
})
export class HighlightDirective implements OnInit{
private elRef:ElementRef;
private defaultColor: 'green';
constructor(elRef:ElementRef){
this.elRef = elRef;
}
ngOnInit():any {
this.elRef.nativeElement.style.color = this.defaultColor;
console.log(this.defaultColor)
}
}