问题
Hi,
I am currently looking to implement something like this (AngularJS):
$routeProvider
.when('/root/:controllerName/blah/:blahId/blah/:blah', {
templateUrl: '/tmpl/:controllerName/blah/partials/:blah' + '.html',
controller: ':controllerName' + 'Ctrl'
})
This is probably overly complicated (with the 'blah, blah, blah') but I wanted to make sure it is clear.
In a nutshell, I'm aiming to accomplish something similar (enough) to how Microsoft MVC employs their routing to controllers -- in other words, very autonomous:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
After that, I intend to LazyLoad the controller (which I have already), but this needs to be (hopefully) compatible with LazyLoading.
Has anyone had success with this approach, know of any resources, or have any ideas about how to accomplish this?
--PreThanks
回答1:
I do not think you will be able to resolve this using ngRoute but I think ngInclude should be able to help:
Html
<div class="slide-animate-container">
<div ng-include="template.url"></div>
</div>
Controller
$scope.template.url = "";//some dynamic rules
Here is a link to angular documentation on this:
https://docs.angularjs.org/api/ngRoute/directive/ngView
来源:https://stackoverflow.com/questions/23705350/angularjs-highly-dynamic-routing