Angular2包中曾经有shims_for_IE
,但是因为rc1被删除了。那么支持IE9 +的解决方法是什么?
IE 11中将渲染模式设置为Edge的错误:
Error: SyntaxError: Syntax error
at ZoneDelegate.prototype.invoke (http://localhost:11111/node_modules/zone.js/dist/zone.js:321:14)
at Zone.prototype.run (http://localhost:11111/node_modules/zone.js/dist/zone.js:216:18)
at Anonymous function (http://localhost:11111/node_modules/zone.js/dist/zone.js:571:18)
Evaluating http://localhost:11111/Scripts/script.js
Error loading http://localhost:11111/Scripts/script.js
IE 11中的错误,渲染模式设置为IE 9:
File: script
Error: Expected ';'
Evaluating http://localhost:11111/Scripts/script.js
Error loading http://localhost:51592/Scripts/script.js
{
[functions]: ,
description: "Expected ';'
Evaluating http://localhost:11111/Scripts/script.js
Error loading http://localhost:11111/Scripts/script.js",
message: "Expected ';'
Evaluating http://localhost:11111/Scripts/script.js
Error loading http://localhost:11111/Scripts/script.js",
name: "Error",
originalErr: { },
stack: null
}
script.js
生成的script.ts
为es6
:
/// <amd-module name="script" />
System.register("script", ['@angular/core', '@angular/platform-browser-dynamic'], function(exports_1, context_1) {
"use strict";
var __moduleName = context_1 && context_1.id;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var core_1, platform_browser_dynamic_1;
var script;
return {
setters:[
function (core_1_1) {
core_1 = core_1_1;
},
function (platform_browser_dynamic_1_1) {
platform_browser_dynamic_1 = platform_browser_dynamic_1_1;
}],
execute: function() {
let script = class script {
constructor(element) {
this.loginUrl = '';
this.antiForgeryName = '';
this.antiForgeryValue = '';
this.loginError = '';
this.submitted = false;
this.loginUrl = element.nativeElement.getAttribute('loginurl');
this.antiForgeryName = element.nativeElement.getAttribute('antiforgeryname');
this.antiForgeryValue = element.nativeElement.getAttribute('antiforgeryvalue');
this.loginError = element.nativeElement.getAttribute('loginError') == null ? "" : element.nativeElement.getAttribute('loginError');
}
};
script = __decorate([
core_1.Component({
selector: 'script',
templateUrl: '/Home/ScriptTemplate.html'
}),
__metadata('design:paramtypes', [core_1.ElementRef])
], script);
exports_1("script", script);
platform_browser_dynamic_1.bootstrap(script);
}
}
});
//# sourceMappingURL=script.js.map
更新
因此改为以下解决了需要垫片的问题:
...
var script = function script() {
function() constructor(element) {
this.loginUrl = '';
this.antiForgeryName = '';
this.antiForgeryValue = '';
this.loginError = '';
this.submitted = false;
this.loginUrl = element.nativeElement.getAttribute('loginurl');
this.antiForgeryName = element.nativeElement.getAttribute('antiforgeryname');
this.antiForgeryValue = element.nativeElement.getAttribute('antiforgeryvalue');
this.loginError = element.nativeElement.getAttribute('loginError') == null ? "" : element.nativeElement.getAttribute('loginError');
}
};
...
但是这看起来像es3
的变换,感谢打字稿是非常不可能的,因为我已经尝试了每一个.d.ts
,它仍然抱怨未找到承诺,设置未找到等等......
见:https://github.com/angular/angular/issues/7280
答案 0 :(得分:0)
轻松修复。从beta.15下载Typings
文件夹并将其放在项目下,然后使用browser.d.ts
或简单地降级到beta.15。虽然我通过安装打字包找到了解决方案,但它在Visual Studio中对我来说并不起作用。