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

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -