angular - Methods on Angular2 class not being recognized -


i have following class in angular2:

export class myclass{  constructor(private a: string, private b: string, private c: string){}      public geta(): string {         return this.a;     }      public getb(): string {         return this.b;     }      public getc(): string{         return this.c;     } 

i using object in component:

myclass myclass = new myclass('some', 'thing',  let path = myclass.geta() != null ? 'foo' :'bar'; 

however, trying run on browser following error in console:

error typeerror: myclass.geta not function

am missing something? in order correct this, way i've found declare variables public (it works private, ide - vs code - indicates error) , use them directly without accessor methods.

you're using wrong syntax (java?) declare variable myclass. should go this:

const myclass:myclass = new myclass('some', 'thing', 'fff');  let path = myclass.geta() != null ? 'foo' :'bar'; 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -