Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing Automapper into a angular2 webpack project

I am trying to use the ts automapper libary in an Angular2 webpack project but not sure how to import it or include it. An example how to accomplish this would be great.

like image 791
doorman Avatar asked Aug 27 '26 06:08

doorman


1 Answers

There maybe be better way to work with this library, however, what I have done in my project is this

   /** 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() {
  }
}

Keep in mind I have amended tsconfig.json file to get that to work.

"moduleResolution": "node",

to

"moduleResolution": "classic",
like image 153
Majid Avatar answered Aug 30 '26 04:08

Majid



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!