如何在Angular2项目中使用Johnny-five

时间:2017-04-04 01:23:30

标签: node.js angular typescript ionic2 johnny-five

请,我是angular2的新手,我需要帮助angular2实施Johnny-Five。

我创建了一个提供程序(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)

任何人都可以指导我如何实施此实施吗?提前谢谢。

0 个答案:

没有答案