angular - How to initialize an array in angular2 and typescript -


why happen in angular2 , typescript?

export class environment {     constructor(       id: string,       name: string     ) { } }    environments = new environment('a','b');    app/environments/environment-form.component.ts(16,19): error ts2346: supplied parameters not match signature of call target. 

how on initialize array?

class definitions should :

export class environment {     cid:string;     cname:string;      constructor( id: string, name: string ) {          this.cid = id;         this.cname = name;     }      getmyfields(){         return this.cid + " " + this.cname;     } }   var environments = new environment('a','b');  console.log(environments.getmyfields()); // print b 

source: https://www.typescriptlang.org/docs/handbook/classes.html


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -