我从rxjs的类中导入,但无效。 因此sendMosaic方法中的.from会导致错误,但我不知道解决方案。
到目前为止,我的代码是这样的:
import { Component, OnInit } from '@angular/core';
import { Account, NEMLibrary, NetworkTypes, Address, AccountHttp, AccountOwnedAssetService, AssetHttp, AssetId, TransferTransaction, TimeWindow, EmptyMessage, TransactionHttp } from "nem-library";
import { Observable, from } from 'rxjs';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
ngOnInit() {
// Initialize NEMLibrary for TEST_NET Network
NEMLibrary.bootstrap(NetworkTypes.TEST_NET);
}
// Send mosaic
sendMosaic = () => {
const privateKey = "";
const address = this.user.address;
const amount = 1;
const account = Account.createWithPrivateKey(privateKey);
Observable
.from([{ mosaic: new AssetId(this.admin.mosaic.nameSpace, this.admin.mosaic.name), quantity: amount }])
.flatMap((_) => new AssetHttp().getAssetTransferableWithAbsoluteAmount(_.mosaic, _.quantity))
.toArray()
.map((mosaics) => TransferTransaction.createWithAssets(
TimeWindow.createWithDeadline(),
new Address(address),
mosaics,
EmptyMessage
))
.map((transaction) => account.signTransaction(transaction))
.flatMap((signedTransaction) => new TransactionHttp().announceTransaction(signedTransaction))
.subscribe(
(value) => {
console.log("Success:" + value.message);
},
(err) => {
console.log("Failed:" + err.toString());
}
);
}
}
编译后抛出错误。
"ERROR in src/app/app.component.ts(71,8): error TS2339: Property 'from' does not exist on type 'typeof Observable'."