skip to Main Content

Using Angular, I have a function being called on click and I’m passing someValue to it.

Example:

<button (click)="callFoo(bar)">Click Me!</button>

Now, my TS code is something like this:

callFoo(gotInput){
    console.log("Print: ", this.someFormGroup.controls.gotInput.value)
}

I’m unable to provide the value fetched to the console.log statement because it says ‘Value is declared but its value is never read’.
How do I go about this?

2

Answers


  1. This should work

    callFoo(gotInput){
        console.log("Print: ", this.someFormGroup.controls[gotInput].value)
    }
    
    Login or Signup to reply.
  2. Your error is because you’re using gotInput wrongly. To fix:

    Instead of this.someFormGroup.controls.gotInput.value, use:

    callFoo(gotInput){
        console.log("Print: ", this.someFormGroup.controls[gotInput].value);
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search