本文介绍了角度2 beta即10“潜在未处理的拒绝[3]语法错误:预期的”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个Angular 2 Beta问题。我起初特别是一般,希望这是一个已知的错误,我只是在我所有的搜索中遗漏了一些东西。当Angular 2 Beta.0问世时,我使用IE10在我的应用程序中运行了一个非常简单的模块。它基本上打印了类似我的第一个模块的东西。

This is an Angular 2 Beta question. I am specifically being general at first in the hope that this is a known error and I just missed something in all my searching. When Angular 2 Beta.0 came out i got a very simple module running in my application using IE10. It basically printed something like "My first module".

当Angular 2 Beta.1问世时,我尝试运行相同的代码并得到以下错误。这发生在Angular2 2.0.0-beta.2& angular2 2.0.0-beta.3还:

When Angular 2 Beta.1 came out I tried the running the same code and got the following error. This happens in Angular2 2.0.0-beta.2 & angular2 2.0.0-beta.3 also:

    EXCEPTION: SyntaxError: Expected ';' 

STACKTRACE:

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

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

-----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相同)是:

The files I am loading (same for Angular 2 Beta.0, Angular 2 Beta.1, Angular 2 Beta.2) are:

<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看起来像:

Update: My boot.ts looks like:

import {bootstrap}    from 'angular2/platform/browser';

import {CountsComponent} from './counts.component';
export function main() {

    bootstrap( CountsComponent );

}

我的counts.component.ts文件如下:

My counts.component.ts file looks like:

  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>

这是一个已知问题吗?它有修复吗?您需要更多信息吗?

Is this a known problem? Does it have a fix? Do you need more info?

推荐答案

我遇到同样的问题。找到了一个快速修复plunker。在plunker示例中的es6-shim.min.js脚本之前插入以下代码:

I have the same problem. Found a quick fix in plunker. Insert following code before es6-shim.min.js script in plunker example:

<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的所有问题。
希望这是一些帮助......

This quick fix does not resolve all the problems with angular 2 and IE.Hope this is some help...

这篇关于角度2 beta即10“潜在未处理的拒绝[3]语法错误:预期的”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 23:44