New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using AutoMapper in Angular2 #17
Comments
Hi doorman02, Thanks for your question. I am currently starting an Angular (v2) project. I will give AutoMapper a shot in the project as soon as the project starts rolling smoothly. Should you be earlier, I hope you wouldn't mind keeping me posted! Cheers, Bert |
I just created a basic Angular app using Angular CI. Getting AutoMapper to function correctly is quite easy, if you follow the guidelines for using an 3rd party library (https://github.com/angular/angular-cli#3rd-party-library-installation). An excerpt:
Now you should be able to use the Ragarding typing: I discovered the AutoMapper's package.json lacks the Cheers, Bert |
Great thanks 👍 |
i'm i missing something ? |
Hi @ricardoccpaiva, Are you trying to use AutoMapperTS with Angular 2 as well? It sounds like you don't have the actual automapper.min.js (or the full version, if you would rather like that) file loaded before actually using it. Did you add the automapper-ts JS file to the scripts array in angular-cli.json as I explained earlier in this thread? Cheers! |
File 'C:/xx/xx/node_modules/automapper-ts/dist/automapper.d.ts' is not a module.) I just followed all your steps carefully and it seems to not be working. |
Hi @ialex90, could you please clarify your situation? It sounds like you are trying to import the definition file itself, which indeed is not a module. The steps mentioned above should do the trick with Angular 2 (#17 (comment)). |
Ey @loedeman thanks for replying, I couldn't make it work and I followed those steps. so few questions are coming to me like, When you mentioned that, what do you mean by 'import the module created in step2'? because in step 2 you say to write on the typings the line to declare the module for the intellisense. Then, I got at the stage where automapper is global, what I can't make is import/use some of your samples like these: It doesn't recognize AutoMapperJs and even doing some tricks and recognizing it, the console says that error I've posted before. Sorry to didn't explain myself before, is it clearer now? |
I found that in order to get it working:
|
Hi @kmacmcfarlane, thanks for your correction, you are absolutely right, can't believe I missed that typo 😉... Cheers, Bert |
If you want to use automapper-ts npm module with webpack directly instead of angular-cli you must follow these steps:
|
Thanks for your help, @bpkinez ! |
My two cents to this conversation: In your tsconfig.json file make sure that you have the following:
I did not have the typings.d.ts file included in the "typeRoots" array. HTH. |
In Angular 6 there's no webpack file
In Angular 6 there's no webpack config file... And I don't know how to include it |
@mikelweb Here is how I got this to work in Angular 6: Install from npm, be sure to use the --save option
Add the declaration in src/typings.d.ts. If the typings file does not exist, create it (it's not created by default with Angular 6 CLI)
If you added the src/typings.d.ts file, you'll need to add it to tsconfig.json typeRoots:
Add minified source to angular.json scripts section, which will load the script:
Import to your component or module:
Use as documented:
(Thanks @loedeman for an awesome component!) |
Wow, @g8rdev, Thanks a lot for your thorough explanation! Thanks a lot for helping out this way, #h5yr! |
Great! Thank you so much for such a good tutorial of how to do it!!! |
Angular 7 not work theses steps |
Hi @loedeman, thanks for the AutoMapper library. I am trying to use it with angular2 and I installed it via npm. My project is a webpack project. Do you have an example on how to use it with angular2?
Thanks!
The text was updated successfully, but these errors were encountered: