简体   繁体   English

Electron app中的Angular2错误:没有PlatformRef的提供者

[英]Angular2 error in Electron app: No Provider for PlatformRef

I'm trying to run very basic angular2 stuff in my existing electron application. 我正试图在我现有的电子应用程序中运行非常基本的angular2东西。 Typescript files are successfully compiled into js code, electron is running fine. 打字稿文件成功编译成js代码,电子运行正常。 All needed files are included in index.html. 所有需要的文件都包含在index.html中。 But I always have an error during app start - No Provider for PlatformRef! 但是我在应用启动时总是出错 - 没有PlatformRef的提供者!

没有PlatformRef的提供者!

I have already checked this link: No provider for PlatformRef error after upgrading to Angular2 RC5 in IE10 我已经检查了这个链接: 在IE10中升级到Angular2 RC5后没有提供PlatformRef错误

I don't have es6-shim dependency, my version of TS package is 2.0.3(latest). 我没有es6-shim依赖,我的TS包版本是2.0.3(最新版)。

Here is what I have. 这就是我所拥有的。

system.config.js system.config.js

(function (global) {
    System.config({
        paths: {
            // paths serve as alias
            'npm:': '../node_modules/'
        },
        // map tells the System loader where to look for things
        map: {
            // our app is within the app folder
            'app': 'app',
            'main': 'app/main.bootstrap.js',

            // angular bundles
            '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
            '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
            '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
            '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
            '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
            '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
            '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
            '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
            'rxjs': 'npm:rxjs',
        },
        // packages tells the System loader how to load when no filename and/or no extension
        packages: {
            app: {
                main: './main.bootstrap.js',
                defaultExtension: 'js'
            },
            rxjs: {
                defaultExtension: 'js'
            }
        }
    });
})(this);

main.bootstrap.ts: main.bootstrap.ts:

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './components2/app.module';

platformBrowserDynamic().bootstrapModule(AppModule);

app.module.ts: app.module.ts:

import {NgModule} from '@angular/core'
import {BrowserModule} from '@angular/platform-browser'
import {FormsModule} from '@angular/forms';
import {RouterModule} from '@angular/router';
import {HttpModule} from '@angular/http';

import {AppComponent} from './app.component';
import {DashboardComponent} from './dashboard.component';

import './rxjs-extensions';

@NgModule({
    imports: [
        BrowserModule,
        FormsModule,
        HttpModule,
        RouterModule.forRoot([
            {
                path: 'dashboard',
                component: DashboardComponent
            },
            {
                path: '',
                redirectTo: '/dashboard',
                pathMatch: 'full'
            }
        ])
    ],
    declarations: [
        AppComponent,
        DashboardComponent
    ],
    bootstrap: [ AppComponent ]
})
export class AppModule {
}

app.component.ts: app.component.ts:

import { Component, OnInit } from '@angular/core';

@Component({
    selector: 'my-app',
    template: '<h1>{{title}}</h1><div class="header-bar"></div>',
    styleUrls: ['']
})
export class AppComponent implements OnInit {
    //component initialization
    ngOnInit() {
        //check authentication
    }

    title = 'Test';
}

Index.jade: Index.jade:

doctype html
html
    head(lang="en")
        meta(charset="UTF-8")
        title
        ....
        script(type='text/javascript').
            System.import('systemjs.config.js').then(function () {
                System.import('main');
            }).catch(console.error.bind(console));
    body
        my-app

Many thanks in advance. 提前谢谢了。

My problem was that one of the files contained reference to 'q-io/fs' npm. 我的问题是其中一个文件包含引用'q-io / fs'npm。 As soon as I removed this usage, angular started working. 一旦我删除了这个用法,角度开始工作。 Very strange.. 很奇怪..

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM