0

I need to modify my object. please check below function

    registerCus(item) {
    this.customer.code = 'B001';
    this.customer.avCode = 'L01';
    this.customer.ageCode = 'A1';
    this.registrationService.customerRequest(item).subscribe(data => {
       
    },
        error => {
            
        });
}

The item, included 3 values: code, avCode, ageCode. When I send the 'item' all three values pass to the service . According to my requirement I need to send only code and avCode. how can I modify 'item' before pass to service.

I am trying to do something like this,

registerCus(item) {
   item  = this.customer.code,  this.customer.avCode;
    this.registrationService.customerRequest(item).subscribe(data => {
    },
        error => {
            
        });
}

2 Answers 2

2

You can use object de-structuring to achieve this behaviour without making any change in the code. You do this in your service method customerRequest;

customerRequest ({code, avCode}) { 
   console.log(code, avCode);
}

Learn more about destructuring in JS.

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

Comments

0

If item and customer are different objects:

registerCus(item) {
    item.code  = this.customer.code;
    item.avCode  = this.customer.code;
    this.registrationService.customerRequest(item).subscribe(data => {
    },
        error => {
            
        });
}

Otherwise you can use Object de-structuring

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.