0

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.

5
  • What do you mean about header? is a property? Commented Dec 15, 2015 at 19:12
  • yes, a new header would be a new name Commented Dec 15, 2015 at 19:16
  • Is this resolved then? Commented Dec 15, 2015 at 19:20
  • Yes. Would you recommend to delete the question? Can I chose my own answer as solution? Thanks. Commented Dec 15, 2015 at 19:26
  • You could add your own answer and mark it as accepted (but read first this info stackoverflow.com/help/self-answer) Commented Dec 16, 2015 at 11:15

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.