简体   繁体   中英

navigate to nested named view with ui-router

In app I have named view mainContent .

    <div class = "wrapper"
         ui-view = "mainContent">
    </div>

I have only one route for this view.

    $stateProvider
        .state("home",
        {
            url: "/home",
            views: {
                'mainContent': {
                    templateUrl: "app/home/home.html"
                }
            }
        });

I load home.html to named view mainContent view which has also named view appContent .

home.html

    <div class = "row"
         ui-view = "appContent">
    </div>

Routes for nested named view appContent are here.

    $stateProvider
        .state("request",
        {
            parent: "home",
            abstract: true,
            url: "/request"
        })
        .state("request.create", {
            url: "/create",
            views: {
                appContent: {
                    templateUrl: "app/requests/create/createRequest.html",
                    controller: "RequestController as vm"
                }
            }
        });

When I try load http://.../#/home/request/create RequestController is not created and also view createRequest.html is not loaded.

From view navigate to request.create state with :

<a ui-sref = "request.create"><i class = "fa fa-plus"></i>New</a>

Thank

Your "request" state needs its own template an ui-view where you can open its child view

$stateProvider
    .state("home",
    {
        url: "/home",
        views: {
            'mainContent': {
                template: "<div class ='row' ui-view ='appContent'></div>"
            }
        }
    })
    .state("request",
    {
        parent: "home",
        abstract: true,
        url: "/request",
        views: {
            'appContent': {
                template: "<div class ='row' ui-view ='requestContent'></div>"
            }
        }
    })
    .state("request.create", {
        url: "/create",
        views: {
            'requestContent': {
                template: "<p>Create Request</p>"
            }
        }
    });

This works for me. Proof: http://jsfiddle.net/eD3MU/373/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM