我正在尝试使用 ts automapper libary在 Angular2 webpack 项目中,但不确定如何导入或包含它。一个如何实现这一点的例子会很棒。
最佳答案
也许有更好的方法来使用这个库,但是,我在我的项目中所做的是这个
/** test.component.ts
** Please note that you need to change Path as this is referenced to my node_module and probably it's different in your end.
**/
/// <reference path="../../../../node_modules/automapper-ts/dist/automapper.d.ts" />
import {Component, OnInit} from '@angular/core';
@Component({
selector: 'test-component',
})
export class TestComponent implements OnInit {
private jsonObj;
constructor() {
automapper.map("JSON", "newType", this.jsonObj);
}
ngOnInit() {
}
}
请记住,我已经修改了 tsconfig.json
文件以使其正常工作。
"moduleResolution": "node",
到
"moduleResolution": "classic",
关于angular - 将 Automapper 导入到 angular2 webpack 项目中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40138293/