3

拜托,我是新手angular2,我需要帮助在angular2.

我创建了一个提供者(J5Provider):

import { Injectable } from '@angular/core';
import 'rxjs/add/operator/map';

var raspi = require('raspi-io');
var j5 = require('johnny-five');

@Injectable()
export class J5Provider {
    private board: any;

    constructor() {
        this.board = new j5.Board({
            io: new raspi()
        });

        this.board.on('ready', function () {
            var led = new j5.Led('P1-7');
            led.strobe(500);
        });
    }
}

然后我尝试app.module.ts在一个Ionic2项目中实例化:

import { NgModule, ErrorHandler } from '@angular/core';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { MyApp } from './app.component';
import { AboutPage } from '../pages/about/about';
import { ContactPage } from '../pages/contact/contact';
import { HomePage } from '../pages/home/home';
import { TabsPage } from '../pages/tabs/tabs';

import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';

import {J5Provider} from '../providers/j5-provider'

@NgModule({
    declarations: [
        MyApp,
        AboutPage,
        ContactPage,
        HomePage,
        TabsPage
    ],
    imports: [
        IonicModule.forRoot(MyApp)
    ],
    bootstrap: [IonicApp],
    entryComponents: [
        MyApp,
        AboutPage,
        ContactPage,
        HomePage,
        TabsPage
    ],
    providers: [
        StatusBar,
        SplashScreen,
        J5Provider,
        {provide: ErrorHandler, useClass: IonicErrorHandler}
    ]
})
export class AppModule {}

但是当我运行时,我收到以下错误:

repl.js:1 Uncaught Error: Cannot find module "repl"
    at v (polyfills.js:3)
    at webpackMissingModule (repl.js:1)
    at Object.<anonymous> (repl.js:1)
    at Object.<anonymous> (repl.js:106)
    at __webpack_require__ (bootstrap c6de802…:19)
    at Object.<anonymous> (board.js:19)
    at Object.<anonymous> (board.js:1269)
    at __webpack_require__ (bootstrap c6de802…:19)
    at Object.<anonymous> (accelerometer.js:1)
    at Object.<anonymous> (accelerometer.js:1175)
    at __webpack_require__ (bootstrap c6de802…:19)
    at Object.noop (johnny-five.js:11)
    at __webpack_require__ (bootstrap c6de802…:19)
    at Object.<anonymous> (app.component.ts:8)
    at __webpack_require__ (bootstrap c6de802…:19)

请任何人指导我如何执行此操作?提前致谢。

4

0 回答 0