ui路由器正在路由但不渲染templateUrl

时间:2015-05-06 17:10:00

标签: angularjs angular-ui-router

我使用这样的UI-Router:

angular.module('app.user.awardee', [
    'ui.router'
])
    .config(
    [          '$stateProvider', '$urlRouterProvider',
        function ($stateProvider,   $urlRouterProvider) {
            $stateProvider
                .state('awardees', {

                    abstract: true,
                    url: '/u/awardee',

                    templateUrl: 'app/user/awardee/awardee.html',

                    resolve: {
                        awardees: ['awardees',
                            function( awardees){
                                return awardees.all();
                            }]
                    },


                    controller: ['$scope', '$state', 'users', 'utils',
                        function (  $scope,   $state,   users,   utils) {

                        }]
                })
                .state('awardees.personaldata', {
                    url: "/personaldata",
                    templateUrl: 'app/user/awardee/personal_info/personal/view.html',
                    controller: ['$scope', '$stateParams', '$state', 'utils', 'access',
                        function ($scope, $stateParams, $state, utils, access) {

                        }]
                })
                .state('awardees.personaldata.edit', {
                    url: "/edit",
                    templateUrl: 'app/user/awardee/personal_info/personal/edit.html',
                    controller: ['$scope', '$stateParams', '$state', 'utils', 'access',
                        function ($scope, $stateParams, $state, utils, access) {

                        }]
                })
                .state('awardees.univerisitydata', {
                    url: "/universitydata",
                    templateUrl: 'app/user/awardee/personal_info/university/view.html',
                    controller: ['$scope', '$stateParams', '$state', 'utils', 'access',
                        function ($scope, $stateParams, $state, utils, access) {

                        }]
                })
                .state('awardees.universitydata.edit', {
                    url: "/edit",
                    templateUrl: 'app/user/awardee/personal_info/university/edit.html',
                    controller: ['$scope', '$stateParams', '$state', 'utils', 'access',
                        function ($scope, $stateParams, $state, utils, access) {

                        }]
                })
                .state('awardees.bank', {
                    url: "/bank",
                    templateUrl: 'app/user/awardee/personal_info/bank/view.html',
                    controller: ['$scope', '$stateParams', '$state', 'utils', 'access',
                        function ($scope, $stateParams, $state, utils, access) {

                        }]
                })
                .state('awardees.bank.edit', {
                    url: "/edit",
                    templateUrl: 'app/user/awardee/personal_info/bank/edit.html',
                    controller: ['$scope', '$stateParams', '$state', 'utils', 'access',
                        function ($scope, $stateParams, $state, utils, access) {

                        }]
                })

        }
    ]
);

我从'awardees.personaldata'路线到'awardees.personaldata.edit', 路线发生了,网址被更改了,但它没有呈现'awardees.personaldata.edit',它呈现'awardees.personaldata'。 控制台没有错误, 我的假是什么?以及如何使它工作?

我使用此代码进行转换:

<a ui-sref="awardees.personaldata.edit" class="btn btn-hollow btn-primary btn-sm">Edit Personal Data</a>

1 个答案:

答案 0 :(得分:2)

我猜想这很可能与失踪的ui-view有关。

父状态的视图,在这种情况下,"awardees.personaldata"必须在某个地方ui-view为孩子 - "awardees.personaldata.edit" - 呈现其内容(就像"awardees" } state的视图有ui-view,我认为它有,因为你可以查看"awardees.personaldata")。

因此,请确保在模板:'app/user/awardee/personal_info/personal/view.html'中有类似的内容:

<div>
  <span>Some data from "awardees.personaldata" state</span>

  <!-- space to render "awardees.personaldata.edit" state -->
  <div ui-view></div>
</div>