这是一个Angular 2 Beta问题。我起初特别是一般,希望这是一个已知的错误,我只是在我所有的搜索中遗漏了一些东西。当Angular 2 Beta.0问世时,我使用IE10在我的应用程序中运行了一个非常简单的模块。它基本上印有类似“我的第一个模块”的东西。
当Angular 2 Beta.1问世时,我尝试运行相同的代码并得到以下错误。这发生在Angular2 2.0.0-beta.2& angular2 2.0.0-beta.3也:
EXCEPTION: SyntaxError: Expected ';'
STACKTRACE:
SyntaxError: Expected ';'
at evalExpression (.../js/angular/angular2/bundles/angular2.dev.js:452:5)
at _createViewFactoryRuntime (.../js/angular/angular2/bundles/angular2.dev.js:24190:9)
at Anonymous function (.../js/angular/angular2/bundles/angular2.dev.js:24144:13)
at run (.../js/angular/angular2/bundles/angular2-polyfills.js:1243:14)
at Anonymous function (.../js/angular/angular2/bundles/angular2.dev.js:13408:15)
at zoneBoundFn (.../js/angular/angular2/bundles/angular2-polyfills.js:1220:14)
at lib$es6$promise$$internal$$tryCatch (.../js/angular/angular2/bundles/angular2-polyfills.js:468:10)
at lib$es6$promise$$internal$$invokeCallback (.../js/angular/angular2/bundles/angular2-polyfills.js:480:10)
at Anonymous function (.../js/angular/angular2/bundles/angular2-polyfills.js:1028:14)
at Anonymous function (.../js/angular/angular2/bundles/angular2-polyfills.js:123:10)
----- async gap -----
Error
at _getStacktraceWithCaughtError (.../js/angular/angular2/bundles/angular2-polyfills.js:2240:10)
at Anonymous function (.../js/angular/angular2/bundles/angular2-polyfills.js:2285:14)
at bind (.../js/angular/angular2/bundles/angular2-polyfills.js:1218:10)
at bindArguments (.../js/angular/angular2/bundles/angular2-polyfills.js:1401:14)
at Anonymous function (.../js/angular/angular2/bundles/angular2-polyfills.js:1413:18)
at Anonymous function (.../js/angular/angular2/bundles/angular2.dev.js:24142:11)
at run (.../js/angular/angular2/bundles/angular2-polyfills.js:1243:14)
at Anonymous function (.../js/angular/angular2/bundles/angular2.dev.js:13408:15)
at zoneBoundFn (.../js/angular/angular2/bundles/angular2-polyfills.js:1220:14)
at lib$es6$promise$$internal$$tryCatch (.../js/angular/angular2/bundles/angular2-polyfills.js:468:10)
----- async gap -----
Error
at _getStacktraceWithCaughtError (.../js/angular/angular2/bundles/angular2-polyfills.js:2240:10)
at Anonymous function (.../js/angular/angular2/bundles/angular2-polyfills.js:2285:14)
at bind (.../js/angular/angular2/bundles/angular2-polyfills.js:1218:10)
at bindArguments (.../js/angular/angular2/bundles/angular2-polyfills.js:1401:14)
at Anonymous function (.../js/angular/angular2/bundles/angular2-polyfills.js:1413:18)
at _compileComponentRuntime (.../js/angular/angular2/bundles/angular2.dev.js:24131:9)
at _compileNestedComponentRuntime (.../js/angular/angular2/bundles/angular2.dev.js:24159:7)
at Anonymous function (.../js/angular/angular2/bundles/angular2.dev.js:24140:13)
at forEach (.../js/angular/es6-shim/es6-shim.min.js:10:16871)
at Anonymous function (.../js/angular/angular2/bundles/angular2.dev.js:24139:11)
----- async gap -----
Error
at _getStacktraceWithCaughtError (.../js/angular/angular2/bundles/angular2-polyfills.js:2240:10)
at Anonymous function (.../js/angular/angular2/bundles/angular2-polyfills.js:2285:14)
at bind (.../js/angular/angular2/bundles/angular2-polyfills.js:1218:10)
at bindArguments (.../js/angular/angular2/bundles/angular2-polyfills.js:1401:14)
at Anonymous function (.../js/angular/angular2/bundles/angular2-polyfills.js:1413:18)
at _compileComponentRuntime (.../js/angular/angular2/bundles/angular2.dev.js:24131:9)
at compileHostComponentRuntime (.../js/angular/angular2/bundles/angular2.dev.js:24085:9)
at compileInHost (.../js/angular/angular2/bundles/angular2.dev.js:24436:7)
at loadAsRoot (.../js/angular/angular2/bundles/angular2.dev.js:12326:7)
at useFactory (.../js/angular/angular2/bundles/angular2.dev.js:12424:9)
----- async gap -----
Error
at _getStacktraceWithCaughtError (.../js/angular/angular2/bundles/angular2-polyfills.js:2240:10)
at Anonymous function (.../js/angular/angular2/bundles/angular2-polyfills.js:2285:14)
at _createInnerZone (.../js/angular/angular2/bundles/angular2.dev.js:13396:7)
at NgZone (.../js/angular/angular2/bundles/angular2.dev.js:13262:9)
at createNgZone (.../js/angular/angular2/bundles/angular2.dev.js:12446:5)
at application (.../js/angular/angular2/bundles/angular2.dev.js:12521:7)
at bootstrap (.../js/angular/angular2/bundles/angular2.dev.js:24631:5)
at main (Unknown script code:9:9)
at Anonymous function (.../communicationReport.do?dispatch=showCommunicationCounts&wsession=new&entityId=10009ndlgxmw:34:14)
at run (.../js/angular/angular2/bundles/angular2-polyfills.js:1243:14)
我加载的文件(Angular 2 Beta.0,Angular 2 Beta.1,Angular 2 Beta.2相同)是:
<script src="js/angular/es6-shim/es6-shim.min.js"></script>
<script src="js/angular/systemjs/dist/system-polyfills.js"></script>
<script src="js/angular/angular2/bundles/angular2-polyfills.js"></script>
<script src="js/angular/systemjs/dist/system.src.js"></script>
<script src="js/angular/rxjs/bundles/Rx.js"></script>
<script src="js/angular/angular2/bundles/angular2.dev.js"></script>
更新:我的boot.ts看起来像:
import {bootstrap} from 'angular2/platform/browser';
import {CountsComponent} from './counts.component';
export function main() {
bootstrap( CountsComponent );
}
我的counts.component.ts文件如下:
import {Component} from 'angular2/core';
@Component({
selector: 'counts',
template: '<h1>Landing Page1</h1>'
})
export class CountsComponent { }
初始html看起来像
<script>
System.config({
transpiler: 'typescript',
typescriptOptions: { emitDecoratorMetadata: true },
packages: {'modules/counts': {
format: 'register',
defaultExtension: 'js'}}
});
System.import('modules/counts/boot')
.then(function( bootstrap ) {
bootstrap.main();
}, console.error.bind(console));
</script>
</head>
<!-- 3. Display the application -->
<body class="counts">
<counts>Loading 1...</counts>
</body>
这是一个已知问题吗?它有修复吗?你需要更多信息吗?
答案 0 :(得分:2)
我有同样的问题。找到了一个快速修复plunker。在plunker示例中的es6-shim.min.js脚本之前插入以下代码:
<script>
if (!Function.name) {
Object.defineProperty(Function.prototype, "name", {
get: function () {
var result = this.toString();
var results = /function (.{1,})\(/.exec(this.toString());
return (results && results.length > 1) ? results[1] : result;
}
});
} else if (navigator.userAgent.indexOf("Trident") != -1) {
console.warn("QUICK FIX NAME ON FUNCTION IS OBSOLETE.");
}
</script>
此快速解决方案无法解决角度2和IE的所有问题。 希望这是一些帮助...
答案 1 :(得分:1)
在角度版本2.0.0-beta.8中解决了问题,包括:
angular2 / ES6的/ dev / SRC /检测/ shims_for_ie.js
不再需要快速修复。