ui router does not put the content in the named ui-view

后端 未结 1 778
[愿得一人]
[愿得一人] 2021-01-25 22:48

When I enter the route

\\#\\projects\\100\\dates\\2014-01-01

in the url and press return I get the \"projects\" state.

I expected to t

相关标签:
1条回答
  • 2021-01-25 23:29

    There is the updated and working plunker, and this is the essential update:

      .state('projects.selected.dates', {
        url: '/dates/:date',
        views: {
          'menu@': {                     // HERE is @ added
            templateUrl: 'menu.html'
          },
          'content@': {                  // HERE is @ added
            templateUrl: 'dateplanner.html',
            controller: 'DateplannerController'
          }
        }
      })
    

    See the '@' at the end of the ui-view name

    The full explanation is here:

    • View Names - Relative vs. Absolute Names (cite)

    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.

    So, what I did is use of the absolute name .. targeting the root - index.html

    Some examples from documentation... greatly explaining that all:

    $stateProvider
      .state('contacts', {
        // This will get automatically plugged into the unnamed ui-view 
        // of the parent state template. Since this is a top level state, 
        // its parent state template is index.html.
        templateUrl: 'contacts.html'   
      })
      .state('contacts.detail', {
        views: {
            ////////////////////////////////////
            // Relative Targeting             //
            // Targets parent state ui-view's //
            ////////////////////////////////////
    
            // Relatively targets the 'detail' view in this state's parent state, 'contacts'.
            // <div ui-view='detail'/> within contacts.html
            "detail" : { },            
    
            // Relatively targets the unnamed view in this state's parent state, 'contacts'.
            // <div ui-view/> within contacts.html
            "" : { }, 
    
            ///////////////////////////////////////////////////////
            // Absolute Targeting using '@'                      //
            // Targets any view within this state or an ancestor //
            ///////////////////////////////////////////////////////
    
            // Absolutely targets the 'info' view in this state, 'contacts.detail'.
            // <div ui-view='info'/> within contacts.detail.html
            "info@contacts.detail" : { }
    
            // Absolutely targets the 'detail' view in the 'contacts' state.
            // <div ui-view='detail'/> within contacts.html
            "detail@contacts" : { }
    
            // Absolutely targets the unnamed view in parent 'contacts' state.
            // <div ui-view/> within contacts.html
            "@contacts" : { }
    
    0 讨论(0)
提交回复
热议问题