IE11 Angular 2错误“预期的标识符,字符串或数字" [英] IE11 Angular 2 error "Expected identifier, string or number"

查看:156
本文介绍了IE11 Angular 2错误“预期的标识符,字符串或数字"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我已经使用Angular 2创建了网站.当我运行"ng-serve"命令并尝试使用" http测试我的网站时, ://localhost:4200 "在Google Chrome和IE11中运行良好,但是,如果我使用"ng-build --prod"构建项目,则将其托管在IIS上.网站仍可在Chrome上运行,但IE11显示以下错误:

Well, I have created site using Angular 2. When I run "ng-serve" command and trying to test my site using "http://localhost:4200" in Google Chrome and IE11 it works perfectly, but, if I build project using "ng-build --prod", host it on IIS. Site still works on Chrome, but IE11 shows the following errors:

我在Google上搜索了它,发现它可能是我的标识符key:value对中的保留字.因此,我在密钥周围添加了Apostrophes('). 例如,我有以下对象:

I googled it and found that it was maybe reserved words in my identifiers key:value pairs. So I added Apostrophes(') arround my keys. For example I had the following object:

user:UserViewModel={
    Username:"",
    Age:0
};
and changed this to:
user:UserViewModel={
    'Username':"",
    'Age':0
};

还删除了key:value对中的最后一个逗号,并在polyfills.ts中导入了core.js

Also deleted last commas in key:value pairs and imported core.js in polyfills.ts

推荐答案

主要问题是IE默认启用了兼容模式. IE 11还有一些兼容模式问题. 按照以下问题答案 Angular 2/4在IE11中不起作用

The main problem is IE has Compatibility Mode enabled by default. And IE 11 has some compatibility mode issues. As per the followings question answer Angular 2 / 4 not working in IE11

当我尝试禁用兼容模式时,它工作正常.

但是普通用户不会退出兼容模式.所以我想要一个好的解决方案.

But ingeneral user will not off the compatibility mode. So I want a good solution for that.

然后我找到了以下解决方案表使用标签强制IE兼容模式

Then I found following solution form Force IE compatibility mode off using tags

      <meta http-equiv="X-UA-Compatible" content="IE=edge" />

这篇关于IE11 Angular 2错误“预期的标识符,字符串或数字"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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