简体   繁体   中英

How to get this example of multiple views working with angularjs' ui-router

I was following these instructions here and cannot get this to work. https://github.com/angular-ui/ui-router/wiki/Multiple-Named-Views

I verified my bootstrap grid divs work by putting them all in index.html and loading the page. Then I "angularfied' it, and the page doesn't render.

I don't see any errors in the javascript console.

To start out with, the page is supposed to look like this. Actual screen shot of the webpage before I split out the views from index.html

在此处输入图片说明

Here is my code after I added angular and created multiple views:

index.html

<html ng-app="stackoverflowApp">
<head>
    <meta charset="utf-8"/>
    <title>stackoverflow Question</title>
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
    <link rel="stylesheet" href="../bower_components/bootstrap/dist/css/bootstrap.css" type="text/css"/>
    <script src="../bower_components/angular/angular.js"></script>
    <script src="../bower_components/angular-ui-router/release/angular-ui-router.js"></script>
    <script src="scripts/stackoverflowApp.js"></script>
</head>
<body>

<div class="container-fluid">

    <div class="row">
        <div ui-view="stackoverflowTopPane"/>
    </div>
    <!-- main panel-->
    <div class="row">
        <!-- Left pane-->
        <div ui-view="stackoverflowLeftPane"></div>
        <!-- content pane-->
        <div ui-view="stackoverflowMainPane"></div>

    </div>
</div>

</body>
</html>

js

'use strict';

angular.module('stackoverflowApp', [
    'ui.router'
])
    .run(
    ['$rootScope', '$state', '$stateParams',
        function ($rootScope, $state, $stateParams) {
            $rootScope.$state = $state;
            $rootScope.$stateParams = $stateParams;
        }
    ]
)
    .config(
    ['$stateProvider', '$urlRouterProvider',
        function ($stateProvider, $urlRouterProvider) {

            /////////////////////////////
            // Redirects and Otherwise //
            /////////////////////////////
            $urlRouterProvider
                .otherwise('/');
            //////////////////////////
            // State Configurations //
            //////////////////////////

            // Use $stateProvider to configure your states.
            $stateProvider

                //////////
                // Home //
                //////////

                .state("home", {

                    views: {
                        'stackoverflowTopPane': {
                            templateUrl: 'so-views/stackoverflow-top-pane.html'
                        },
                        'stackoverflowLeftPane': {
                            templateUrl: 'so-views/stackoverflow-left-pane.html'
                        },
                        'stackoverflowMainPane': {
                            templateUrl: 'so-views/stackoverflow-main-pane.html'
                        }
                    }
                })

        }
    ]
);

As far as I can see, you never assign the "home" state the index.html URL. Try setting url: "/", just before "views"

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