我使用VS模板创建的Angular 2 ASP.NET Core应用程序中的Polyfills.ts是否缺失?

时间:2017-10-16 07:13:07

标签: angular asp.net-core

我是Angular开发的新手,我使用Visual Studio 2017 Professional模板开始使用ASP.Net Core创建Angular 2应用程序: enter image description here

我的问题是应用程序无法在Internet Explorer 11上运行并且搜索我发现我必须在[HttpGet] [Route("students")] [SwaggerOperation(Tags = new[] { "Student" })] [SwaggerResponse(HttpStatusCode.OK, Type = typeof(ResponseModel<IList<Student>>))] [SwaggerResponseExample(HttpStatusCode.OK, typeof(StudentResponseExample))] [SwaggerResponse(HttpStatusCode.InternalServerError)] public IHttpActionResult SearchStudent() { IDictionary<string, string> searchParams = null; searchParams = ControllerContext.GetQueryStrings(); . . . } 文件上取消注释。

我在polyfills找到了它,但它没有预期的相同内容(如此SO answer中显示的内容)。

使用VS模板是否是一个好主意,或者我可以使用Empty模板并将Angular应用程序添加到其中?

2 个答案:

答案 0 :(得分:6)

我遇到了同样的问题 - 幸运的是修复很简单。

polyfills.ts文件放在与boot.browser.ts文件相同的目录中(我在临时目录中运行ng new test-app命令只是为了获取最新文件),而不是添加以下行在boot.browser.ts文件的顶部: -

import './polyfills';

然后,您必须删除polyfills.ts文件中已注释掉的位,以包含您要支持的浏览器所需的导入,并运行所需的npm install命令(在polyfills.ts)中的行注释中指定。

那应该为你解决IE11问题。

您提到使用空模板然后使用ng new创建应用程序,但在Visual Studio中进行(和调试)并不是一项简单的任务,因此您可能会感觉更好如果你沿着那条路走下去,请使用VS Code。如果您可以部署到支持.net corenode.js的环境,那么您最好使用.net核心Angular模板。

答案 1 :(得分:4)

如果您没有polyfills.ts个文件,请阅读this

您必须打开ClientApp-->boot.browser.ts文件。

第2行

  

import&#39; zone.js&#39;;

添加此

&#13;
&#13;
/** IE9, IE10 and IE11 requires all of the following polyfills. **/
import 'core-js/es6/symbol';
import 'core-js/es6/object';
import 'core-js/es6/function';
import 'core-js/es6/parse-int';
import 'core-js/es6/parse-float';
import 'core-js/es6/number';
import 'core-js/es6/math';
import 'core-js/es6/string';
import 'core-js/es6/date';
import 'core-js/es6/array';
import 'core-js/es6/regexp';
import 'core-js/es6/map';
import 'core-js/es6/set';

/***********added*************/
&#13;
&#13;
&#13;

这应该有效