how to combine these angularjs, visual studio & no

2020-07-26 15:18发布

问题:

I am coming from MVC background and has recently started development using angularjs. I am using Visual Studio for the WebApi development and using MVC from angularjs. The basic template for hosting webapi i had picked from: here

But now i dont have any way for minification & bundling, which would in production drastically hamper the app load time. Is there any way to use minification & bundling with angularjs & webapi without using MVC.

While looking for solution i came across "Node.Js Tools for Visual Studio" which seems to came to my rescue. Now i am having separate projects for webapi and angularjs. i am using node.js for build & testing purposes. npm for installing packages in angular project & nuget for installing any dependencies for webapi project. Now, I can do all the development in visual studio.

But I am still not sure about few things:

  1. how do i make connect between webapi & angularjs. i need to host both in different ports and do the CORS from angularjs.

  2. if i make a change in webapi, will i have to host it again and then test it... is there no easy way out?

Btw, combining visual studio with node.js - is that a bad idea? should i keep the mvc with webapi and angularjs in same visual studio project and using mvc bundling-minification... so i am not worried about hosting & deployment.

Note: I am using NHibernate and have to connect with Oracle. is there any other option that i can try apart from webapi which can make the things easier.

Sorry for my lack of knowledge on how the things on overall level works.. how do these threads combine, and thanks for helping me out. I have done enough googling but was not able to find out a solution. if somebody can point me to some articles it would be great.

回答1:

  1. AngularJs is built perfectly for communicating with RESTful web apis. Look at the $http and $resource providers. If you are communicating cross domain, you will have to set up CORS in your web api application.
  2. If your project is set up that your angular app is also served by your web api server, you can debug local, make and deploy changes together, etc.
  3. Node.js is a great solution for non-mvc bundling, linting and minification, but nuget does the same thing as npm, and in most cases, it's more suitable for the visual studio experience.
  4. If you're using node.js, you can pretty much wrap anything you like to communicate with oracle.