Reputation: 682
I am trying to add an additional header to an array of objects that contain the headers to my table.
My question is, how would I add a header, manually to the same object property 'name'?
I tried to initialize the array before push, but that does not give me the first element.
Example:
vm.headers = ["Products"];
angular.forEach(vm.metadata, function (value, key) {
//headers
vm.headers.push({
name: value.DataFieldTitle,
});
});
Many thanks.
UPDATE:
I was initializing the array incorrectly. I got it to work like:
vm.headers = [{Name: "Products"}];
And the rest of the code stay the same.
Upvotes: 0
Views: 3606
Reputation: 682
I had to look closer to what I was doing, and the simplest way I thought this could be done is by just initializing the array with the value I wanted to have at first position, and then just append the database values.
So the way my solution looks:
vm.headers = [{name: "Products"}];
angular.forEach(vm.metadata, function (value, key) {
//headers
vm.headers.push({
name: value.DataFieldTitle,
});
});
Thank you.
Upvotes: 1