页面的某些部分在角子视图 [英] Parts of page as subviews in Angular
问题描述
我有以下问题要解决:
从本地菜单(菜单左侧)内我可以选择子页面。典型情况。现在,我想relaod与当地的菜单项关联的内容。在纯粹的角度,我不知道一个标准简单的方法来实现它。我可以从服务器获取手动标记,手动替换内容区域。有没有更好的办法?我一派,横渡
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路由器这个问题。
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的路由器使用嵌套的状态。事情是这样的。
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'
})
所以,你的意见/ /home.html的里面,你可以把一个元素与用户界面视图
指令。那么这个元素将包含子状态的意见( 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
).
这篇关于页面的某些部分在角子视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!