In my controller, I make a rest call to create my table. I need to append some fixed rows and I dont know how to do it.
I want something like 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 do I add an array to the 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 with cloud is from the server. So close but should look like this:
[ { "id": "111", "name": "staging" },{ "id": "86aa96e8-0383-4bce-b833-be3c21f47306", "name": "cloud" } ]
This worked but is there a better way?:
this.environmentService.getEnvironments()
.subscribe(environments => {
for (var i = 0; environments.length > i; i++)
{ this.environments.push(environments[i])}
},null,() => { this.isLoading = false; });