Parts of page as subviews in Angular(部分页面作为 Angular 中的子视图)
问题描述
我有以下问题要解决:
从本地菜单(左侧菜单)中,我可以选择子页面.典型场景.现在我想重新加载与本地菜单项相关的内容.在纯 Angular 中,我不知道实现它的标准简单方法.我可以手动从服务器获取标记并手动替换内容区域.有没有更好的办法?我google了一下,发现了
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 中的子视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:部分页面作为 Angular 中的子视图


基础教程推荐
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01