2017-11-10 154 views
0

我嘗試在一個新的角度4應用 我做了什麼來實現bitcoinjs-lib(,,???):無法解決所有參數ECPair:

npm install bitcoinjs-lib --save 
npm install @types/bitcoinjs-lib --save 

我app.component.ts:

import { Inject } from '@angular/core'; 
import { Component } from '@angular/core'; 
import { HDNode, Transaction, ECPair } from 'bitcoinjs-lib' 

@Component({ 
    selector: 'app-root', 
    templateUrl: './app.component.html', 
    styleUrls: ['./app.component.css'] 
}) 
export class AppComponent { 
    title = 'app'; 

    constructor(private ecPair: ECPair){ 
    console.log(this.ecPair.getAddress()) 
    } 
} 

編譯成功,但我在瀏覽器中得到:

Uncaught Error: Can't resolve all parameters for ECPair: (?, ?, ?). 
    at syntaxError (compiler.js:466) 

這裏是ECPair在node_modules :

export class ECPair { 
    constructor(d: BigInteger, Q?: null, options?: { compressed?: boolean, network?: Network }); 

    constructor(d: null | undefined, Q: any, options?: { compressed?: boolean, network?: Network }); // Q should be ECPoint, but not sure how to define such type 

    d: BigInteger; 

    getAddress(): string; 
... 
} 

據我所知,他不知道如何實例化它,因爲differents參數類型,我該如何解決它?我用@Inject嘗試過,但無法解決。

謝謝

回答

1

您必須正確提供。在你@NgModule你應該使用這樣的事情:

@NgModule({ 
    ... 
    providers: [ 
    ... 
    { ECPair, useFactory:()=>new ECPair(d,Q,options) } 
    ] 
}) 

指定dQoptions適當的參數。

相關問題