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
Post a Comment