简体   繁体   English

使用事件发射器时无法运行我的Angular 2应用程序

[英]Unable to run my Angular 2 application when using Event Emitters

I've run into an issue where my application will no longer load after adding a service that utilizes Event Emitters. 我遇到了一个问题,在添加使用事件发射器的服务后,我的应用程序将不再加载。 The error I get is as follows: 我得到的错误如下:

"SyntaxError: expected expression, got '<'
Evaluating http://localhost:3000/node_modules/angular2/ts/src/facade/async
Error loading http://localhost:3000/app/main.js" angular2-polyfills.js:138:14

SyntaxError: expected expression, got '<'

My Main.ts file where I do the application bootstrapping looks like this: 我用来执行应用程序引导的Main.ts文件如下所示:

import {bootstrap} from "angular2/platform/browser"
import {provide} from "angular2/core";
import {ROUTER_PROVIDERS} from "angular2/router"

import {AppComponent} from "./app.component"
import {LocalStorageService} from "./core/localstorage.service";
import {PersistenceService} from "./core/persistence.service";

bootstrap(AppComponent, [
    ROUTER_PROVIDERS,
    LocalStorageService,
    provide(PersistenceService, {useExisting: LocalStorageService})
]);

The service where I'm using Event Emitters looks like this: 我使用事件发射器的服务如下所示:

import {Injectable, Output} from "angular2/core";
import {EventEmitter} from "../../node_modules/angular2/ts/src/facade/async";

@Injectable()
export class GlobalActionsService {
    @Output() saveSettings: EventEmitter<any> = new EventEmitter();
    @Output() loadSettings: EventEmitter<any> = new EventEmitter();

    doSave() {
        this.saveSettings.emit(null);
    }

    doLoad() {
        this.loadSettings.emit(null);
    }

}

And finally, my index.html looks like this: 最后,我的index.html看起来像这样:

<html>
    <head>
        <!-- Set the base href for routing -->
        <base href="/">

        <title>MyApp</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <!-- 1. Load stylesheets -->
        <link rel="stylesheet" type="text/css" href="./public/bootstrap/bootstrap.min.css">
        <link rel="stylesheet" type="text/css" href="./public/css/custom.css">

        <!-- 2. Load libraries -->
        <script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
        <script src="node_modules/systemjs/dist/system.src.js"></script>
        <script src="node_modules/rxjs/bundles/Rx.js"></script>
        <script src="node_modules/angular2/bundles/angular2.dev.js"></script>
        <script src="node_modules/angular2/bundles/router.dev.js"></script>

        <!-- 3. Configure SystemJS -->
        <script>
            System.config({
                packages: {
                    app: {
                        format: 'register',
                        defaultExtension: 'js'
                    }
                }
            });
            System.import('app/main').then(null, console.error.bind(console));
        </script>
    </head>

    <!-- 4. Display the application -->
    <body>
        <my-app>Loading...</my-app>
    </body>
</html>

I'm not sure if my problem is related to how I'm bootstrapping the app, my usage of Event Emitters, or something else entirely...if anyone can shed some light as to what the problem might be here, it would be greatly appreciated! 我不确定我的问题是否与我如何引导应用程序,事件发射器的使用或其他完全有关...如果有人可以阐明问题的根源,那就是不胜感激!

您需要导入EventEmitter这样(从Angular2的核心模块):

import {Injectable, Output, EventEmitter} from "angular2/core";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 与事件发射器一起使用诺言 - Using promises with event emitters javascript 承诺是否使用事件发射器工作? - Do javascript promises work using event emitters? 如何要求另一个模块中的一个使用事件发射器? - How to require one module in the other for using event emitters? 在AngularJs中更新大型数据集时,事件发射器与$ watch - Event emitters vs $watch when updating large data sets in AngularJs 如何在节点中测试事件发射器 - How to test event emitters in node 什么时候应该使用多个事件名称与不同的事件发射器? - When should I use multiple event names vs different event emitters? 当我使用 Angular Material 和一些自定义它的代码时,如何解决 angular 应用程序中的 $event 问题 - How to solve out the $event issue in angular application when I'm using and Angular Material and some code customizing it 无法使用 Angular 服务处理 onbeforeunload 事件 - Unable to handle onbeforeunload event using Angular Service 事件发射器与并行执行的承诺? - Event Emitters vs Promises for parallel execution? 使用 event.preventDefault 时无法从 Laravel 应用程序注销。 替代? - Unable to logout from Laravel application when using event.preventDefault. Alternative?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM