angular - Angular2 and typescript - how to add an array to a array from promise? -


in controller, make rest call create table. need append fixed rows , dont know how it.

i want this:

export class environment { id: string; name: string; }

environments: any[];  production = new environment('1', 'production'); development = new environment('2', 'development');      ngoninit(){             this.environmentservice.getenvironments()                 .subscribe(environments => this.environments = environments,null,() => { this.isloading = false; });          }  

so how add array promise result?"

  [this.production,this.development] + this.environments; 

results of proposed solution:

 staging: environment = {         id: '111',         name: 'staging' };  environments = [this.staging];  [ { "id": "111", "name": "staging" }, [ { "id": "86aa96e8-0383-4bce-b833-be3c21f47306", "name": "cloud" } ] ] 

the name cloud server. close should this:

[ { "id": "111", "name": "staging" },{ "id": "86aa96e8-0383-4bce-b833-be3c21f47306", "name": "cloud" } ] 

this worked there better way?:

this.environmentservice.getenvironments()             .subscribe(environments => {                 (var = 0; environments.length > i; i++)                  { this.environments.push(environments[i])}              },null,() => { this.isloading = false; }); 

you're looking array.concat():

this.environmentservice.getenvironments()   .subscribe(env => { this.environments = this.environments.concat(env); },     null,     () => { this.isloading = false; }   ); 

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 -