I'm continuing to read the Adam Freeman book on angular but again stuck with the example around form validation using FormGroup, as presume it used to work but now 2 versions on typescript doesn't like it.
I can see what it is trying to do, after clicking the submit button it gets each form value and assigns them back onto my Product object. hence using the index ['name'] type approach. If I actually put the value of 'name', 'category' or 'price' in the place of c against this.newProduct, it works fine but then I also need the other two values to be updated.
Object.keys(this.formGroup.controls)
.forEach(c => this.newProduct[c] = this.formGroup.controls[c].value)
My product object looks like this
export class Product {
constructor(public id?: number,
public name?: string,
public category?: string,
public price?: number) {}
}
How can I make this work in an understandable way?
I have found this link but I cant seem to fathom if I can use it or not.
Element implicitly has an 'any' type because expression of type 'string' can't be used to index
The approach documented in the book does feel overly complex and clunky, just give me some C# :)
