angular - 将 Automapper 导入到 angular2 webpack 项目中

标签 angular webpack

我正在尝试使用 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/

相关文章:

angular - 如何使用 Angular 服务提供 leaflet 或 google maps 等第三方 API?

angular - 如何停止在 Angular 垫片中添加新值和重复值?

javascript - 有没有办法在 webpack 中自动导入 'cssuseragent' (或任何未导出的)包?

javascript - Webpack:如何从 css-loader 导出 css 文件?

javascript - Webpack 插件开发 - 函数调用父函数的参数

javascript - TypeScript 中的 findIndex 数组方法

javascript - Angular,如何使用基于 bool 值的指令

Angular 元素与 Angular 库?

css - Webpack 将 CSS 编译成奇怪的类名

reactjs - 如何在 create-react-app 中禁用热重载?