这些页面实际上是静态的HTML(虽然它们是由Rails呈现的),然后一些Angular 2组件被放置到页面中.从Angular 1开始,我们简单地将文档元素引导到一个模块,该模块提供了我们需要的指令和组件.根本没有路由.
与角2,它看起来像是全部或全部.您声明一个单一的根组件,一切都通过该组件渲染.这对我们来说是一个很大的转变,我想避免在这些面向公众的网页上改变我们在做什么.
在静态HTML页面中,是否可以根据需要使用Angular 2组件,或者我们需要移动到单根根元素SPA设计?
Bootstrapping Multiple Applications
When working within a browser window,there are many singleton
resources: cookies,title,location,and others. Angular services that
represent these resources must likewise be shared across all Angular
applications that occupy the same browser window. For this reason,
Angular creates exactly one global platform object which stores all
shared services,and each angular application injector has the
platform injector as its parent.Each application has its own private injector as well. When there are
multiple applications on a page,Angular treats each application
injector’s services as private to that application.
所以很明显,这是可能的,多个应用程序共享服务资源,这是我希望的.
我已经做了一些微不足道的测试与多个自举组件,它的工作正常.我还没有尝试的一件事是引导Angular 2 attribute directive在Angular 2组件之外使用.我怀疑这不行,引导只适用于组件而不是指令.
在指导方面,我建议Angular 2不是真正设计用于在静态页面中喷洒行为,可能不应该这样使用.相反,虽然您可能有多个应用程序定义的分页的多个部分,但该组件应该占据几乎所有的文档/界面.