1

I would like to use angular templates for most of my application, but for some pages I'd want to use aspnet mvc controllers and partial views displayed in the ng-view.

I've been trying things like this with the routing:

when('/AccountX/Manage', { templateUrl: '/Account/Manage', controller: AccountController }).
when('/Account/Manage', { controller: AccountController }).

I've also changed the Account/Manage forms to be ajax, but it seems after posting a form, angular proceeds with a get.

I'm using html5Mode without hashbangs. My aim is to have always normal urls.

Is there a way to tell angular to avoid some routes? Like IgnoreRoute in aspnet MVC?

Sorry if I'm too vague. For my own understanding, I just want to find a working concept of mixing standard aspnet mvc with angular regardless if it's considered good or bad.

2 Answers 2

1

Looks like there are ways to use the $location service to accomplish what you are requesting:

Conditionally have anchor links send user to a different page, rather than load to ng-view

Sign up to request clarification or add additional context in comments.

1 Comment

The target attribute doesn't help for managing problems with form posts. It does work fine for the arbitrary link thou.
0

It seems a big part of making it work is to avoid assigning ng-app to the html element. When the ng-app is smaller, the parts outside it will not be affected by the routing.

There are some potential issues along the way:

  • ng-app can't be nested.
  • only the first ng-app becomes automatically bootstrapped.
  • latter ng-app is instead added like this: angular.bootstrap(element[, modules]);

http://docs.angularjs.org/api/ng.directive:ngApp
http://docs.angularjs.org/api/angular.bootstrap

When there are links within the ng-app that should not trigger the angular routing, it's avoided by adding target="_self" (or any target attribute).

There is a good project template for mvc4+angular+breeze available which can be studied and tested. (At least VS 2012 Update 2 is required for it.)
http://www.asp.net/single-page-application/overview/templates/breezeangular-template

Conclusion

By partitioning the application within the html page such that there are parts that isn't affected by the routing, and excluding individual links within an ng-app when needed, Asp.NET MVC functionality can successfully be mixed with AngularJS.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.