在angularjs中嵌套ng-view

时间:2021-11-17 19:38:27

I'm trying to have two angular apps to one page.

我正在尝试将两个角度应用程序放到一个页面上。

my scenario: i having a website which is having lot of apps. so for eg header, footer, left sidebar, right sidebar will not change for the whole webpage, only the content will change. so i used angular templating(ng-view). while clicking on the app like calendar, it will be loaded in the ng-view. in the calendar app i have a ng-view for different views(month,week,day) so it will be like

我的场景:我有一个拥有大量应用程序的网站。所以对于例如页眉,页脚,左侧边栏,右侧边栏不会改变整个网页,只有内容会改变。所以我使用了角度模板(ng-view)。在点击日历等应用程序时,它将被加载到ng-view中。在日历应用程序中,我有一个不同视图(月,周,日)的ng视图,所以它会是这样的

<ng-view>
    calendar or some other app
    <ng-view>
        month or week or day or SOMEOTHER APP TEMPLATE
    </ng-view>
</ng-view>

when i tried this the browser is crashed. Is there any way to achieve this?

当我尝试这个时,浏览器崩溃了。有没有办法实现这个目标?

1 个解决方案

#1


1  

ngView is coupled with $routeProvider, which means that it is updated according to the current route/uri. Which also means you cannot bind two different views to a single URI.

ngView与$ routeProvider结合,这意味着它根据当前路由/ uri进行更新。这也意味着您无法将两个不同的视图绑定到单个URI。

You can just use ngInclude with a url that you want to show. It works same as ngView in terms of fetching from server.

您可以将ngInclude与要显示的网址一起使用。它在从服务器获取方面与ngView相同。

You would not download all of the 3 urls at once if you just provide the url, it would be fetched on demand.

如果你只是提供网址,你不会一次下载所有3个网址,它将按需提取。

However, in most of the applications, it is better to serve all the possible static files at once and then cache it, which would result in overall better performance; only the initial load would suffer a bit; which is better than a slow application in general.

但是,在大多数应用程序中,最好一次提供所有可能的静态文件然后缓存它,这将导致整体更好的性能;只有初始负载会受到一点影响;这比一般的慢速应用要好。

I would prefer to wait 2 more seconds if that would make the whole application respond faster.

如果这会使整个应用程序响应更快,我宁愿等待2秒钟。

#1


1  

ngView is coupled with $routeProvider, which means that it is updated according to the current route/uri. Which also means you cannot bind two different views to a single URI.

ngView与$ routeProvider结合,这意味着它根据当前路由/ uri进行更新。这也意味着您无法将两个不同的视图绑定到单个URI。

You can just use ngInclude with a url that you want to show. It works same as ngView in terms of fetching from server.

您可以将ngInclude与要显示的网址一起使用。它在从服务器获取方面与ngView相同。

You would not download all of the 3 urls at once if you just provide the url, it would be fetched on demand.

如果你只是提供网址,你不会一次下载所有3个网址,它将按需提取。

However, in most of the applications, it is better to serve all the possible static files at once and then cache it, which would result in overall better performance; only the initial load would suffer a bit; which is better than a slow application in general.

但是,在大多数应用程序中,最好一次提供所有可能的静态文件然后缓存它,这将导致整体更好的性能;只有初始负载会受到一点影响;这比一般的慢速应用要好。

I would prefer to wait 2 more seconds if that would make the whole application respond faster.

如果这会使整个应用程序响应更快,我宁愿等待2秒钟。