简体   繁体   English

没有路线的 Angular 应用

[英]Angular app without routes

I have an application which needs to be able to dynamically add directives/filters/services/controllers.我有一个需要能够动态添加指令/过滤器/服务/控制器的应用程序。 The functionality I need is akin to loading a Mac OS X Widget / Windows Gadget.我需要的功能类似于加载 Mac OS X 小工具/Windows 小工具。 To my knowledge there are 3 ways of doing this :据我所知,有 3 种方法可以做到这一点:

  • Include them in the initial stack -- This isn't realistic for me, as the stack will be too big, and we may be pulling these functionalities from remote locations on demand将它们包含在初始堆栈中——这对我来说不现实,因为堆栈太大,我们可能会根据需要从远程位置提取这些功能

  • Hack a bit, and add them to the application -- I have this working, but it's messy when you have to recompile.稍微修改一下,然后将它们添加到应用程序中——我有这个工作,但是当您必须重新编译时会很麻烦。 An adapted version of Loading an AngularJS controller dynamically动态加载 AngularJS 控制器的适配版本

  • Bootstrap another app with has all the needed functionality -- Probably the most correct way of doing this... Bootstrap 另一个具有所有所需功能的应用程序——可能是最正确的方法......

Right now, I'm sticking to the third option.现在,我坚持第三种选择。

These asynchronously added apps don't need routes.这些异步添加的应用程序不需要路由。 What's the best way to write these modules, so I don't have to configure $routeProvider?编写这些模块的最佳方法是什么,所以我不必配置 $routeProvider? What do I use instead of ng-view?我用什么来代替 ng-view?

Or do I have to just stick using $routeProvider.otherwise() ?还是我必须坚持使用$routeProvider.otherwise()

Thanks,谢谢,

Max.最大限度。

check out my blog post walking through a simple app with a decoupled feature defining its own state: angularjs-state-management-with-ui-router .查看我的博客文章,介绍一个简单的应用程序,该应用程序具有定义自己状态的解耦功能: angularjs-state-management-with-ui-router

The technique shown is to provide a state hierarchy per feature and implement this in said module's config .显示的技术是为每个功能提供一个状态层次结构,并在所述模块的config实现它。

Also, look at script.js : not strictly an angular script loader, but plays well with it (as demonstrated in the angular-seed app: deep link to implementation .) This might help you to solve the dynamic loading problem.另外,看看script.js :严格来说不是一个角度脚本加载器,但可以很好地使用它(如 angular-seed app: deep link to implementation 中所示。)这可能会帮助您解决动态加载问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM