1
emailData.contractors = [
                    0: {
                         id: 1,
                         email: asd@asd
                       }
                    1: {
                         id: 1,
                         email: asd@asd
                       }
                  ]
emailSub(event, data) {
    const trigger = $(event.target);
    this.emailData.contractors.forEach((v, i) => {
      if (v.id == data.id) {
        this.emailData.contractors[0]['subject'] = trigger.val();
      }
    });
  }

Expected Output

                    0: {
                         id: 1,
                         email: asd@asd
                         subject: 'sdf'
                       }
                    1: {
                         id: 1,
                         email: asd@asd`enter code here`
                       }
                  ]

How can i achive this in angular 8. the function above is not working on a keyup of an input from which i get the data

1
  • 1
    [ 0: { is not valid syntax Commented Apr 22, 2020 at 5:56

2 Answers 2

1

Use Object.assign to add an property.

Try like this:

emailSub(event, data) {
   const trigger = $(event.target);
   let item = this.emailData.contractors.find(x => x.id == data.id);
   Object.assign(item, {'subject':trigger.val()})
}

Working Demo

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

Comments

0

change your data to

emailData.contractors = [
                {
                     id: 1,
                     email: "asd@asd"
                },
                {
                     id: 2,
                     email: "asd@asd"
                }
              ]

Or

emailData.contractors = {
                0: {
                     id: 1,
                     email: "asd@asd"
                },
                1: {
                     id: 2,
                     email: "asd@asd"
                }
              }

1 Comment

is my function should work,,,, those data is for example ... i got the emailData.contractors from an api like this ``` data: [,…] 0: {company: "ABC Maintenance", address: "17/52 Holker Street", preferred: 0, phone: "(03) 9508 5588 ",…} 1: {company: "AZ Electrician", address: 13, preferred: 0, phone: "(02) 9875 0000 ", fax: "9522 1111",…} 2: {company: "AZ Plumbing", address: "Sydney", preferred: 0, phone: "(02) 9443 8899 ", fax: "9887 6677",…} ```

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.