嵌套 fxLayout 容器的好习惯?

good practice to nest fxLayout containers?

我最近开始第一次使用 angular/flex 并且不确定布局容器嵌套。在下面的代码中,导航标签是一个 angular-material sidenav,它在左侧打开,然后将其余内容推到右侧。我在这一点上注意到(当我刚开始时它不是这样的)当我 opening/closing 它时,sidenav 最近似乎有点滞后。它在动画中途冻结了几秒钟,然后 opens/closes 完全冻结。我在一行 fxLayout 容器中嵌套了列和多行 fxLayout 容器,我认为这可能是 sidenav 动画性能问题的原因?我是否通过嵌套所有这些导致性能问题的容器使事情变得过于复杂?

我的代码:

<div fxLayout fxAlign="start start">
    <mat-toolbar color="primary">
        <button mat-icon-button (click)="toggleSidenav()">
            <mat-icon aria-label="menu">
                <i class="material-icons">restaurant_menu</i>
            </mat-icon>
        </button>
        <span>POC Toolbar</span>            
        <span class="fill-remaining-space"></span>
        <div class="rhs">
            <mat-icon class="rhs-icon fa fa-home fa-lg"></mat-icon>
            <span class="rhs-item">Home</span>  

            <mat-icon class="rhs-icon fa fa-sign-out fa-lg" aria-hidden="true"></mat-icon>
            <span class="rhs-item">Logout</span>

            <mat-icon class="rhs-icon fa fa-key fa-lg"></mat-icon>
            <span class="rhs-item">Password</span>

            <mat-icon class="rhs-icon fa fa-sitemap fa-lg"></mat-icon>
            <span class="rhs-item">Site map</span>          
        </div>  
    </mat-toolbar>
</div>

<div fxLayout="row"  fxLayoutAlign="start" fxLayoutGap="20px">
    <div fxFlex>
        <navigation [state]="showMenu"></navigation>
    </div>

    <div fxFlex="100%">
        <div fxLayout="column" fxLayoutGap="20px">
            <div>
                <h1>Dashboard</h1>
            </div>
            <div>
                <p>Lorem ipsum dolor sit amet, eum iuvaret delicata at. Eu postea commodo persius mei. Id est semper constituto, ignota aperiri adversarium ne vix. Id est impetus suscipit, nulla meliore epicuri id eos. Ad pro modo albucius atomorum. At mel ullum libris debitis, in vero apeirian mediocrem mei.</p>
            </div>
            <div>
                <p>Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Cras mattis consectetur purus sit amet fermentum. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh.</p>
            </div>
            <div>
                <h2>Sample Angular/Flex Column Layout</h2>
            </div>
        </div>
        <div fxLayout fxLayoutGap="15px">
            <div fxFlex="33%">              
                    <h3>Notes</h3>
                    <ul>
                        <li>we're using responsive css &amp; Angular(Angular-material &amp; Angular/flex) This allows us to show (or hide) things like the left menu and the number of columns displayed by dataTables.</li>
                        <li>The amount of "Custom" css we've used is actually very little, prefering rather to make use of the framework's built in features.</li>
                        <li>Angular reactive forms and validators should probably replace the generic php form.</li>
                        <li>No server side php is used.</li>
                    </ul>
            </div>
            <div fxFlex="33%">
                <h3>Example views</h3>
                <ul>
                    <li><a href="#">Login Screen</a></li>
                    <li><a href="#">Home Page</a> &raquo; Ledger system &raquo; Sales ledger &raquo; Customer master files</li>
                    <li><a href="#">Customer Master Search</a></li>
                    <li><a href="#">Customer Master List</a></li>
                    <li><a href="#">detail Customer Master</a></li>
                    <li><a href="#">update Customer Master</a></li>
                    <li><a href="#">detail Account</a> - Click on suburb <i class="fa fa-info-circle"></i></li>
                    <li><a href="#">Lookup Screen(Generic)</a> - Click on suburb <i class="fa fa-search"></i></li>
                </ul>
            </div>
            <div fxFlex="33%">
                <h3>Keyboard Shortcuts</h3>
                <ul>
                    <li><Ctrl + b: Go back/li>
                    <li>Ctrl + i: Launch info</li>
                    <li>Ctrl + h: Launch help</li>
                    <li>Ctrl + l: Show or hide menu</li>
                    <li>Ctrl + n: Add new item</li>
                    <li>Ctrl + p: Print</li>
                    <li>Ctrl + r: reload table data</li>
                    <li>Ctrl + <em>any other</em> page specific function you ned</li>
                </ul>
            </div>
        </div>
    </div>
</div>

my navigation component html:


<mat-sidenav-container position="start" class="custom-sidenav-container">

    <mat-sidenav #sidenav mode="side" opened="false">
        Navigation
        <ul class="sn-list">
            <li>                    
                <mat-icon class="sn-item">
                    <i class="material-icons">dashboard</i>
                </mat-icon>
                <a class="sn-item" href="#">Dashboard</a>       
            </li>
            <li>

                <mat-icon class="sn-item">
                    <i class="material-icons">archive</i>
                </mat-icon>             
                <span class="sn-item" [matMenuTriggerFor]="stockSystemMenu">Stok System</span>

                <mat-menu [overlapTrigger]="false" #stockSystemMenu="matMenu">
                    <button mat-menu-item>
                        <mat-icon class="sn-item">
                            <i class="material-icons">chevron_right</i>
                        </mat-icon>
                        <span class="sn-item">Service 1</span>
                    </button>
                    <button mat-menu-item>
                        <mat-icon class="sn-item">
                            <i class="material-icons">chevron_right</i>
                        </mat-icon>
                        <span class="sn-item">Service 2</span>
                    </button>
                    <button mat-menu-item>
                        <mat-icon class="sn-item">
                            <i class="material-icons">chevron_right</i>
                        </mat-icon>
                        <span class="sn-item">Service 3</span>
                    </button>
                </mat-menu>
            </li>           
            <li>
                <mat-icon class="sn-item">
                    <i class="material-icons">shopping_cart</i>
                </mat-icon>
                <span class="sn-item" [matMenuTriggerFor]="salesMenu">Sales / Purchases</span>
                <mat-menu [overlapTrigger]="false" #salesMenu="matMenu">
                    <button mat-menu-item>
                        <mat-icon class="sn-item">
                            <i class="material-icons">chevron_right</i>
                        </mat-icon>
                        <span class="sn-item">Service 1</span>
                    </button>
                    <button mat-menu-item>
                        <mat-icon class="sn-item">
                            <i class="material-icons">chevron_right</i>
                        </mat-icon>
                        <span class="sn-item">Service 2</span>
                    </button>
                    <button mat-menu-item>
                        <mat-icon class="sn-item">
                            <i class="material-icons">chevron_right</i>
                        </mat-icon>
                        <span class="sn-item">Service 3</span>
                    </button>
                </mat-menu>         
            </li>       </ul>
    </mat-sidenav>
    <div class="sn-content">    
    </div>
</mat-sidenav-container>

通常您将关联的主要内容包装在 mat-sidenav-container.

material docs 有一些例子。

在您的情况下,您发布的所有视图代码,或者可能只是您的仪表板代码,都应该包含在 mat-sidenav-container