严格模式下不允许属性的多个定义-Angular [英] Multiple definitions of a property not allowed in strict mode - Angular

查看:316
本文介绍了严格模式下不允许属性的多个定义-Angular的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在IE的Angular(6)项目中遇到了此问题,这导致应用程序无法加载.它仅在应用程序的产品构建中发生,由Angular连接并缩小.在"ng serve"下运行的本地dev版本不会导致此问题.此错误是在Chrome开发者控制台中:

I ran into this in my Angular (6) project in IE, which caused the app to not load. It only occurred in the prod build of the app, which is concatenated and minified by Angular. The local dev version running under 'ng serve' did not cause the issue. This error was in the Chrome dev console:

SCRIPT1046: Multiple definitions of a property not allowed in strict mode
File: main.51c74b0704ecaa189364.js, Line: 1, Column: 1263758

这是缩小的主脚本中它所指的位置:

Here was the location in the minified main script it was referring to:

(6,{"col-6":0,"col-6":1})

推荐答案

我发现我的ngClass在一些地方为不同的评估设置相同的类.我有一个通用的库函数mobile(),用于确定我们是在移动设备上还是在小型桌面上,并相应地设置类(尤其是Bootstrap列,边距,填充等).例如:

I found I had a few places where my ngClass was setting the same class for different evaluations. I have a common library function mobile() which I use to determine if we are on a mobile device or small desktop, and set my classes accordingly (particularly Bootstrap columns, margins, padding, etc). For instance:

<div [ngClass]="{'col-12': mobile(), 'col-6': !mobile()}">

在某些情况下,我在某些地方都使用了相同的类,如下所示:

There were a few places where I had used the same class for both cases, like below:

<div [ngClass]="{'col-6': mobile(), 'col-6': !mobile()}">                            

我意识到Bootstrap具有诸如col-sm-6和col-md-6之类的类以启用类似的变体,但这与这里无关.如果两个案例都被分配了相同的类,则这些类可以命名为"foo",这就是导致问题的原因.一旦将上面的内容重构为仅使用一个类,就很好了.

I realize Bootstrap has classes such as col-sm-6 and col-md-6 to enable similar variations, but that's irrelevant here. The classes could be named 'foo', if both cases were assigned that same class, that's what was causing the problem. Once I refactored the above to just use a class, it was fine.

<div class='col-6'>

就根本原因而言,我不知道但欢迎任何投入.奇怪的是,有一次我因(重复的标识符"col-6" )破坏了构建而遇到了编译器错误.但是此代码中没有编译器错误,它可以干净地构建和部署,并且仅影响IE.我发现它的唯一方法是在错误附近寻找一些未缩小的HTML文本,以了解从何处开始寻找.

As far as a root cause goes, I have no idea but welcome any input. Strangely I once ran into a compiler error due to this (Duplicate identifier ''col-6'') that broke the build. But there were no compiler errors in this code, it built and deployed clean and only affected IE. The only way I found it was by looking for some unminified HTML text near the error to get an idea of where to start looking.

这篇关于严格模式下不允许属性的多个定义-Angular的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆