1

I have an Object:

public countriesSignup = [{
    name: 'countries',
    options: [
        {text: 'Customer', value: '1'},
    ]
}];

My Final Object must be:

countriesSignup = [{
    name: 'countries',
    options: [
        {text: 'Customer', value: '1'},
        {text: 'Contractor', value: '2'},
    ]
}];

How i can add from Controller? I try this:

this.countriesSignup['options'] = [{text: 'Contractor', value: '2'}] ;

2 Answers 2

2

You can directly use .push since options is an array

this.countriesSignup[0].options.push({text: 'Contractor', value: '2'});
Sign up to request clarification or add additional context in comments.

Comments

1

Mistake#1

You are using Array of object, so you have to mention index also

So it should be

this.countriesSignup[0]

Mistake #2 Since options is array, you should use push

countriesSignup[0].options.push({})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.