Question: I have an app that I put together with ASP.NET MVC 4/5, but now I have hit some issues and think AngularJS will give me solution and create additional opportunities. I want to therefore keep ASP.NET MVC doing stuff server-side but hand things down to the client-side for Angular to handle and post back.
Short Answer: Think again.
Longer Answer: I recently embarked on this mission and am now sat here writing this post having only got a few hours sleep. Turns out you can’t really just “add Angular” on top of an existing ASP.NET MVC 4/5 solution as easily as I had hoped. There’s certain ‘Angular ways’ of doing things and you can either refactor to do it the Angular way or you can fight against it, and probably lose, which is what happened to me many times.
Though I am happy with the resulting changes, it’s probably fair to call it an almost wholesale rewrite of the application to support decoupling from the tightness of ASP.NET MVC. In fact, I’m not really using the MVC part of ASP.MVC much now. Instead, I’m using WebApi to pass objects down to my AngularJS controllers from where they are handled and posted back as nice neat models for the server to handle. My Controllers up on ASP.NET MVC are now tiny (yay!) and my Views just act as placeholders/containers/controller wrappers for Angular to do its stuff.
Bottom line: Don’t do this when you’ve got a project and a deadline unless you know Angular very well. I came at it from cold last week and it’s nearly killed me getting up to speed and re-writing stuff at the same time. Fools rush in. I was a fool.
But it’s all good in the end with hard work and long hours.