我目前将HorizonIO导入到我的Range2项目中的方式如下:
var horizon = require('@horizon/client');
@Injectable()
export class DbService {
private horizon;
constructor() {
this.horizon = Horizon({host: 'localhost:8181'});
}
}现在我不觉得这是正确的方式,因为我应该能够
import { Horizon } from '@horizon/client';虽然它不会抛出错误,但是变量是不可用的。
思想/评论?
发布于 2017-03-20 13:49:19
的ES6导入等效值
var Horizon = require('@horizon/client');是
import * as Horizon from '@horizon/client';你所做的相当于
var Horizon = require('@horizon/client').Horizon;编辑:
我现在使用以下代码使视界可以注入:
import { Injectable } from '@angular/core';
import * as Hz from '@horizon/client';
@Injectable()
export class Horizon extends Function {
private _hz;
constructor() {
super('...args', 'return this._hz(...args)');
this._hz = new Hz({host: 'localhost:8181'});
return this.bind(this);
}
}然后注入并调用它,就像直接导入它时一样:
constructor(hz: Horizon){
hz('messages').watch().subscribe(...);
}不太确定这是否比直接导入Horizon有任何好处,但使用DI会让人感到更不明智。
发布于 2017-03-08 11:03:47
检查@horizon/client是否在您的node_modules文件夹中,如果没有:尝试npm install (https://www.npmjs.com/package/@horizon/client)。
https://stackoverflow.com/questions/42669221
复制相似问题