【问题标题】:strange build time error in angular 5 appAngular 5应用程序中的奇怪构建时间错误
【发布时间】:2018-08-30 03:44:55
【问题描述】:

我正在开发一个应用程序,我从 http 请求中获取对象并将其转换为像这样的可迭代数组。当我在开发模式下运行应用程序时,代码有时会运行并给出如下所示的随机错误。但是当我运行 ng build --prod 时,它总是给我以下错误,因此我被卡住了。

我错过了什么?

         Object.keys(res['com'][element]['schema']['properties']).forEach(inputKey => {
              this.newfdata[element]['properties'].push(res['com'][element]['schema']['properties'][inputKey]);

        }



       // this is line no. 223
                this.objectProps = Object.keys(res['com'][element]['schema']['properties']).map(prop => { 

          return Object.assign({}, { key: prop} , res['com'][element]['schema']['properties'][prop]);

        // this is line no. 228
          });

由于上述行,我收到以下错误。

ERROR in src/app/shared/layout/add.component.ts(223,5): error TS1005: ',' expected.
src/app/shared/layout/add.component.ts(228,11): error TS1005: ')' expected.

请帮助我。由于这个问题,整个应用程序没有进入 prod 模式。

提前致谢。

【问题讨论】:

  • 该错误可能是因为您之前编写的其他代码。也许你有一个没有正确关闭的功能?

标签: angular typescript build production


【解决方案1】:

您在关闭输入键功能之前关闭了 forEach,可能是导致错误的原因,如下所示更改第 223 行顶部的行,希望这能解决问题。

 Object.keys(res['com'][element]['schema']['properties']).forEach(inputKey => {
          this.newfdata[element]['properties'].push(res['com'][element]['schema']['properties'][inputKey]

    }); // close forEach 



   // this is line no. 223
            this.objectProps = Object.keys(res['com'][element]['schema']['properties']).map(prop => { 

      return Object.assign({}, { key: prop} , res['com'][element]['schema']['properties'][prop]);

    // this is line no. 228
      });

【讨论】:

  • 是的,这就是问题所在。感谢您伸出援手。奇怪的是 TS 在开发模式下忽略了这一点。
猜你喜欢
  • 1970-01-01
  • 2016-06-06
  • 2018-04-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-25
  • 2011-05-22
相关资源
最近更新 更多