页面的一部分作为 Angular 中的子视图 [英] Parts of page as subviews in Angular
问题描述
我有以下问题需要解决:
I have the following problem to solve:
从本地菜单(左侧菜单)中,我可以选择子页面.典型场景.现在我想重新加载与本地菜单项相关的内容.在纯 Angular 中,我不知道实现它的标准简单方法.我可以手动从服务器获取标记并手动替换内容区域.有没有更好的办法?我用谷歌搜索并发现
From within local menu (menu on the left) I can choose sub pages. Typical scenario. And now I would like to relaod content associated with local menu item. In pure Angular I don't know a standard easy way to achieve it. I could get markup from the server manually and replace the content area manually. Is there a better way? I googled and came across
https://github.com/angular-ui/ui-router
在我开始深入研究细节之前,也许您可以建议如何解决这个问题.或者甚至建议我是否可以使用 ui-router 解决这个问题.
Yet before I start delving into details perhaps you could advice how to solve this problem. Or even advice if I can solve this issue with ui-router.
推荐答案
您想在 ui-router 中使用嵌套状态.像这样
You want to use nested states in with ui-router. Something like this
$stateProvider
.state('home', {
templateUrl: 'views/home.html',
url: '/home',
controller: 'homeCtrl'
})
.state('home.localmenu1', {
templateUrl: 'views/localmenu1.html',
url: '/home/local1',
controller: 'local1Ctrl'
})
.state('home.localmenu2', {
templateUrl: "views/localmenu2.html",
url: '/home/local2',
controller: 'local2Ctrl'
})
.state('products', {
templateUrl: 'views/products.html',
url: '/products',
controller: 'productsCtrl'
})
因此在您的views/home.html"中,您可以使用 ui-view
指令放置一个元素.然后这个元素将包含子状态的视图(home.localmenu1
,home.localmenu2
).
So inside your "views/home.html" you can put an element with the ui-view
directive. Then this element will contain the views of the sub-states (home.localmenu1
, home.localmenu2
).
这篇关于页面的一部分作为 Angular 中的子视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!