我有一个角度服务,我想从中使用普通的javascript模块。
当我从构造函数中实例化它时,我得到以下错误:
TypeError: Engine is not a constructor
我的服务如下:
import { Injectable } from "angular2/core";
import * as Engine from './engine';
@Injectable()
export class MyService {
constructor() {
this.engine = new Engine(); // causing error
}
doStuff() {
return this.engine.doStuff();
}
}
我的模块代码:
var _ = require('lodash');
function Engine() {
this.stuff = [];
};
WorkoutEngine.prototype.doStuff = function() {
console.log('do stuff');
};
module.exports = Engine;
我无法弄清楚我哪里出错了?
答案 0 :(得分:0)
因为您正在尝试将Engine注入MyService的构造函数,
@Injectable()
export class MyService {
// Let angular inject the engine.
constructor(private engine: Engine) {
}
.....
}