typescript - angular 2 custom directive OnInit -
i'm getting starting on angular 2 , i'm encountering following problem.
below simple custom directive supposed color font green. in ngoninit, can't access string "defaultcolor", console.log returns "undefined".
any clue why?
cheers!
import {directive, elementref, oninit} '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) } }
the syntax wrong.
private defaultcolor:string = 'green';
the value assigned using =
not :
. :
define type field.
Comments
Post a Comment