Home > Mobile >  Element implicitly has an 'any' type because expression of type 'string' can
Element implicitly has an 'any' type because expression of type 'string' can

Time:04-27

hasError(typeofvalidator:string, controlname:string) : boolean 
{
    return his.CustomerModel.formCustomerGroup.contains[controlname].hasError(typeofvalidator);
 }

I'm Learning Angular, In the course video has same code but it is running in the course but I'm getting the Error. I don't know what I'm doing wrong need help please.

CodePudding user response:

To debug this, break up each step into several strongly typed variables.

hasError(typeofvalidator:string, controlname:string) : boolean 
{
  const customerModel: {formerCustomerGroup: string} = this.CustomerModel;

  const fCG: string = customerModel.formCustomerGroup;

  return fCG.contains[controlname].hasError(typeofvalidator);
}

I don't know why yours doesn't work, and I'm sure that mine won't work either for whatever reasons yours doesn't work, but it will break up the problem into a spot that's very identifiable and then you can work from there.

When you've fixed it, you can change it back to the shorter version if you like, but here you've hit a snag, and it's time to go searching.

Good hunting!

CodePudding user response:

Maybe try replacing the square brackets [] after your contains with normal parentheses ()? Looks like the error says you're trying to index a function.

So should maybe look more like this:

return this.CustomerModel.formCustomerGroup.contains(controlname).hasError(typeofvalidator);

After this I assume your initial error will be resolved, but there might be another one.

  • Related