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 中的子视图
				
        
 
            
        - addEventListener 在 IE 11 中不起作用 2022-01-01
 - CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
 - Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
 - Fetch API 如何获取响应体? 2022-01-01
 - Flexslider 箭头未正确显示 2022-01-01
 - 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
 - 400或500级别的HTTP响应 2022-01-01
 - Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
 - 失败的 Canvas 360 jquery 插件 2022-01-01
 - 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
 
						
						
						
						
						