Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS SPA with ASP.NET Web API back-end

I am new to AngularJS and need some advice on how to structure a SPA with Web API for an internal order entry system (SEO not a concern). I would like to set this up in a clean, well-structured fashion for efficient development, debug & deployment.

Here is what I am planning to do:

  • Not use MVC / razor views (leave all routing and rendering to Angular)
  • Create two separate Visual Studio (2013) solutions: one just for the AngularJS SPA portion and one for Web API portion (for serving all data to the SPA).

As an alternative, I guess I could use one Visual Studio solution for the full site (both SPA and WebAPI) and then use razor to serve the html files (or figure out how to disable the default MVC plumbing and serve straight HTML instead, to avoid the MVC overhead). Also, would I then have to put both the SPA and the WebAPI in the same project to be able to debug with Visual Studio easily?

Or perhaps there is a better approach?

Advice on best practices / good approaches on this would be appreciated.

like image 956
Jim Balo Avatar asked Aug 15 '14 03:08

Jim Balo


People also ask

Can we use AngularJS with ASP NET?

Using AngularJS in ASP.NETAfter selecting Web, select ASP.NET Web Application (. NET Framework) under The Web. We need to give the project name in name column, which looks, as shown below. Project template Window will open after clicking OK button.

How does Angular project connect to Web API?

Open Visual Studio >> File >> New >> Project >> Select Web Application. After that click OK and you will see the templates. Select the Web API template. Click OK.

Is Angular good for spa?

Answer: Yes. All the sites created with Angular are SPAs. AngularJS is defined in the SPA framework.


1 Answers

We have created a two different projects under the same solution , First one is the empty web application and the next one is a class library .

1) Web application project consists of angular JS and the other client side components .

2) Class library consists of the Web api controllers and the relevant components such as filters and the other details.

We have a bootstrap class in the class library project which bootstraps the webapi and the container for us. Also it makes the testing of Web api easily

   public class Bootstrap
   {
        public void ConfigureRoute(HttpConfiguration httpConfiguration)
        {
        }

        public BootStrapApplication ConfigureContainer()
        {
        }
   }

From the global.asax in the app_start we call the BootStrap application class and the method .

For application structure on angularjs i found the John papa guide efficient https://github.com/johnpapa/angularjs-styleguide

Hope this helps

like image 78
satish Avatar answered Oct 04 '22 23:10

satish