AngularJS: Highly Dynamic Routing

我与影子孤独终老i 提交于 2019-12-11 10:03:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!