带有角度ui路由器的md-tab不呈现孙子代 [英] md-tabs with angular ui-router not rendering grandchildren

查看:67
本文介绍了带有角度ui路由器的md-tab不呈现孙子代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Angular 1.6.2与Angular Material 1.3一起使用,并且大量使用了组件.我有一个外部"appComponent",它包装了应用程序的其余部分,并提供了带有导航,页脚的标题工具栏,然后将我的顶级应用程序组件加载到应用程序组件内部的ui视图中.

I am using Angular 1.6.2 with Angular Material 1.3 and making fairly heavy use of components. I have an outer "appComponent" that wraps the rest of the app and provides a header toolbar with navigation, a footer and then my top-level app components load within a ui-view inside the app component.

我的组件之一是客户维护页面,该页面在选项卡1的选项卡中具有列表,然后在选项卡2的特定于客户的详细信息.

One of my components is a customer maintenance page that has a list in a tab on tab 1 and then customer specific details on tab 2.

选项卡2通过ng-include加载另一个模板,该模板包含多个选项卡.其中一些标签包含子数据,我想延迟加载它们,因此我为它们创建状态如下:

tab 2 loads another template via ng-include that includes several tabs. A few of those tabs contain child data and I want to lazy load them, so I create states for them like this:

 .state('customers', {
                url: "/customers",
                templateUrl: "components/customer/index.html",
                role: "customers",
                resolve: { authenticate: authenticate }
            })
            .state('customers.customer', {
                url: "/{customerId}",
                templateUrl: "components/customer/index.html",
                role: "customers - edit",
                view: "customerdetail",
            })
            .state('customers.customer.acknowledgements', {
                url: "/acknowledgements",
                templateUrl: "components/customer/customerAcknowledgements.html",
                view: "customeracknowledgements",
                onEnter: function() {
                    debugger
                }
            })
            .state('customers.customer.importinstructions', {
                url: "/importinstructions",
                templateUrl: "components/customer/customerImportInstructions.html",
                role: "customers - edit",
                view: "customerImportInstructions",
            })
            .state('customers.customer.orderhistory', {
                url: "/orderhistory",
                templateUrl: "components/customer/customerOrderHistory.html",
                // parent resolve is inherited. Not implementing
                view: "customerOrderHistory",
            })

html包含具有每个视图名称参数的ui视图,如下所示:

The html inlcudes ui-view with the name argument for each view like so:

        <md-tabs md-dynamic-height class="md-primary" md-no-select-click md-selected="selectedTab">
            <md-tab label="General Info">
                <!-- content removed for the sake of brevity -->
            </md-tab>
            <md-tab>
                <md-tab-label><span ui-sref="customers.customer.acknowledgements">Acknowledgements</span></md-tab-label>
                <md-tab-body>
                    <div ui-view name="customeracknowledgements"></div>
                    <!--<div ui-view></div>-->
                </md-tab-body>
            </md-tab>
            <md-tab layout-fill ui-sref="customers.customer.importinstructions" label="Import Instructions" md-on-select="$ctrl.selectTab('customers.customer.importinstructions')">
                <md-tab-body>
                    <div ui-view name="customerImportInstructions"></div>
                </md-tab-body>
            </md-tab>
            <md-tab label="Order History" ui-sref="customers.customer.orderhistory" md-on-select="$ctrl.selectTab('customers.customer.orderhistory')">
                <md-tab-body>
                    <div ui-view=n ame "customerOrderHistory">
                    </div>
                </md-tab-body>
            </md-tab>
        </md-tabs>

我尝试了各种各样的事情.我知道状态也在被导航,因为我已经在每个状态的customeracknowledgements状态上使用了onEnter函数,并且每个状态都会触发该函数.另外,如果我在Chrome开发人员工具中观看了网络"标签,那么当我导航到包含标签时,会执行XHR调用来检索每个模板,但是任何标签上均未显示任何内容.

I have tried a wide variety of things. I know that the states are being navigated too because I've had the onEnter function used on the customeracknowledgements state on each state and it fires for each one. Also if I watch the network tab in the Chrome developer tools an XHR call is made to retrieve each template when I navigate to the containing tab, but nothing is display on any of the tabs.

我已经搜索了*#%!因此,请阅读并尝试我能找到的所有内容,但没有任何帮助.任何想法,将不胜感激.

I've googled the *#%! out of this, read and tried everything I can find, but nothing has helped. Any ideas would be appreciated.

推荐答案

我能够通过更改如下视​​图语法来使其正常工作:

I was able to get this working by changing the view syntax like this:

            .state('customers.customer.acknowledgements', {
                url: "/acknowledgements",
                role: "customers - edit",
                views: { "customeracknowledgements": 
                    { templateUrl: "components/customer/customerAcknowledgements.html" } },
            })

让模板加载到选项卡主体中并保留所有动画效果的最不冗长的方法似乎是:

and the least verbose way to get the templates to load within the tab bodies and keep all of the animation effects appears to be:

            <md-tab label="Acknowledgements" ui-sref="customers.customer.acknowledgements">
                <md-tab-body>
                    <div ui-view name="customeracknowledgements"></div>
                </md-tab-body>
            </md-tab>

这篇关于带有角度ui路由器的md-tab不呈现孙子代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆