加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular – tslint/codelyzer/ng lint错误:“for(… in …)语句

发布时间:2020-12-17 08:01:42 所属栏目:安全 来源:网络整理
导读: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) {
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)) {

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读