angular – tslint/codelyzer/ng lint错误:“for(… in …)语句必须使用if语句进行过滤”

前端之家收集整理的这篇文章主要介绍了angular – tslint/codelyzer/ng lint错误:“for(… in …)语句必须使用if语句进行过滤”前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Lint错误消息:

src/app/detail/edit/edit.component.ts[111,5]: for (… in …)
statements must be filtered with an if statement

代码段(这是一个工作代码.它也可以在angular.io form validation section获得):

for (const field in this.formErrors) {
      // clear prevIoUs error message (if any)
      this.formErrors[field] = '';
      const control = form.get(field);

      if (control && control.dirty && !control.valid) {
        const messages = this.validationMessages[field];
        for (const key in control.errors) {
          this.formErrors[field] += messages[key] + ' ';
        }
      }
    }

知道如何解决这个lint错误吗?

应用@Helzgate的回复的一种更简洁的方法可能是用’替换你的’for .. in’
for (const field of Object.keys(this.formErrors)) {

猜你在找的Angularjs相关文章