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

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

问题描述

好吧,我已经使用 Angular 2 创建了站点.当我运行ng-serve"命令并尝试使用

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:

我用谷歌搜索,发现它可能是我的标识符键:值对中的保留字.所以我在我的键周围添加了撇号(').例如我有以下对象:

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
};

还删除了键值对中的最后一个逗号并在 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天全站免登陆