html partial is not loaded into ui-view

[亡魂溺海] 提交于 2019-12-09 04:35:33
Radim Köhler

As we've discussed it here:

the issue is related to the:

In our case, we can fix this example by extending the child states (day, week, month) resp. their view names to be targeting the absolute view names target:

   .state('dates.day', {
    url: '/day',
    views: {
      'planner@dates': {
         ...
      }
    }
  })
    .state('dates.week', {
    url: '/week',
    views: {
      'planner@dates': {
         ...
      }
    }
  })
    .state('dates.month', {
    url: '/month',
    views: {
      'planner@dates': {
         ...
      }
    }

Because these views target is in the state dates we are adding its name after delimiter @, i.e. 'planner@dates'. Also, because this state is parent of all of them, we can skip it. Parent state is behind the scene injected for us by ui-router. Some more explanation:

Behind the scenes, every view gets assigned an absolute name that follows a scheme of viewname@statename, where viewname is the name used in the view directive and state name is the state's absolute name, e.g. contact.item. You can also choose to write your view names in the absolute syntax.

Quick overview

  1. The ui-view="content" placed in index.html is getting the absolute name "content@". The delimiter is @ and state is root represented as "" (string empty). I.e. viewname@statename ===`"content@"

  2. The dates children can target parent like "planner@dates" or "planner". They also can target root like "content@"

Please see here http://plnkr.co/edit/8a898K4F0zz1z9VcH9Tq?p=preview what was the reason to use @ in view name ?

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

        $urlRouterProvider.otherwise('/dateplanner/day');

        $stateProvider
          .state('dates', {
            url: '/dateplanner',
            abstract: true,
            views: {
              'menu': {
                templateUrl: 'menu.html'
              },
              'content': {
                templateUrl: 'dateplanner.html',
                controller: 'DateplannerController'
              }
            }
          })
           .state('dates.day', {
            url: '/day',
            views: {
              'planner': {
                templateUrl: 'dateplannerday.html',
                controller: 'DateplannerDayController'
              }
            }
          })
            .state('dates.week', {
            url: '/week',
            views: {
              'planner': {
                templateUrl: 'dateplanner.week.html',
                controller: 'DateplannerWeekController'
              }
            }
          })
            .state('dates.month', {
            url: '/month',
            views: {
              'planner': {
                templateUrl: 'dateplanner.month.html',
                controller: 'DateplannerMonthController'
              }
            }
          })
      });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!