2017-02-26 110 views
0

enter image description here我有兩個col頁眉和頁腳佈局。標題具有頁面導航(GetStarted,Component)。其中一列是sidenav,另一列是主要內容。 當「GetStarted」 NAV是活動的,sidenav填充有 當「分量」 NAV是活動的,sidenav被填充有各自的鏈路(複選框,警報)Angular UI-Router:嵌套視圖

在點擊「概述」鏈接各個鏈路(概述,實施例)區域被填充有其數據

<ul class="nav nav-tabs"> 
     <li role="presentation" class="active"><a href="#checkbox--default">Default</a></li> 
     <li role="presentation"><a href="#checkbox--disabled">Disabled</a></li> 
    </ul> 

    <section class="content__main__tab__content col-xs-12 col-sm-12 col-md-12 col-lg-12"> 
     <form id="checkbox--default"> 
     <div class="input__checkbox--default" id="checkbox--default"> 
     <!-- <div class="form-group"> --> 
      <fieldset> 
      <legend>Default</legend> 
       <label for="gi-checkbox">Checkbox Label 
       <div class="checkbox-input-wrapper group__input-wrapper"> 
        <input type="checkbox" class="checkbox" id="gi-checkbox"> 
       </div> 
       </label> 
      </fieldset>    
     <!-- </div> --> 
     </div> 
     </form> 
</section> 

主要內容有2周NAV的選項卡checbox狀態(默認&禁用)。通過點擊「默認」,它的內容必須顯示,並禁用相同的內容。我是新角度,我有點第一級嵌套視圖工作。但是整個事情無法奏效。這裏是代碼樣品

的index.html

<body ng-app="mendouiApp" id="mendo__home" data-spy="scroll" data-target=".scrollspy">  
     <nav class="navbar navbar-fixed-top navbar-inverse"> 
      <div class="container"> 
      <div class="navbar-header"> 
       <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> 
       <span class="sr-only">Toggle navigation</span> 
       <span class="icon-bar"></span> 
       <span class="icon-bar"></span> 
       <span class="icon-bar"></span> 
       </button> 
       <a class="navbar-brand" ui-sref="home"><img src="images/gi-logo.png" alt="logo"/></a> 
      </div> 
      <div id="navbar" class="collapse navbar-collapse"> 
       <ul class="nav navbar-nav"> 
       <li class="active"><a ui-sref="home">Get Started</a></li> 
       <li><a ui-sref="components">Components</a></li> 
       </ul> 
      </div><!-- /.nav-collapse --> 
      </div><!-- /.container --> 
     </nav><!-- /.navbar --> 

     <div class="wrapper" ui-view></div> <!--/.container--> 

component.html

<div class="content__wrapper"> 
     <div class="row"> 
      <div class="content__secondary content__secondary--l scrollspy"> 
       <ul id="sidenav-fixed-l" class="nav hidden-xs hidden-sm affix-top" data-spy="affix"> 
       <li> 
        <h5>COMPONENTS</h5> 
       </li> 
       <li ng-repeat="item in componentsList"> 
        <a ui-sref="{{item.link}}" ng-cloak>{{item.name}}</a> 
       </li> 
       </ul> 
      </div> 
      <div ui-view></div>  
     </div> <!--/.row--> 
     </div> <!--/.content-wraper--> 

app.js

(function(){ 
    var mendouiApp = angular.module('mendouiApp', ['ui.router', 'ui.router.stateHelper']); 

    mendouiApp.constant('COMPONENTS_LIST', { 
     name: 'sidenav', 
     templateUrl: '../components/components.list.html', 
     abstract: true, 
     children: [{ 
      name: 'alerts', 
      url: '/alerts', 
      templateUrl: '../components/alerts/alerts.html' 
     }] 
    }); 

    mendouiApp.config(function($stateHelperProvider, $urlRouterProvider, $locationProvider, $urlMatcherFactoryProvider, COMPONENTS_LIST) { 
     $urlMatcherFactoryProvider.strictMode(false); 
     $urlRouterProvider.otherwise('/home'); 
     $locationProvider.hashPrefix('!'); 
     $stateHelperProvider 
      .state('home', { 
       url: '/home', 
       templateUrl: '../gettingstarted.html', 
       controller: 'getStartedController' 
      }) 
      .state('layouts', { 
       url: '/layouts', 
       templateUrl: '../layouts.html' 
      }) 
      .state('screenpatterns', { 
       url: '/screenpatterns', 
       templateUrl: '../screenpatterns.html' 
      }) 
      .state('yogi', { 
       url: '/yogi', 
       templateUrl: '../yogi.html' 
      }) 
      .state('components', { 
       url: '/components', 
       templateUrl: '../components.html', 
       controller: 'componentsController' 
      }) 
      .state(COMPONENTS_LIST, { 
       keepOriginalNames: true 
      }) 
      .state('components.button', { 
       url: '/button', 
       templateUrl: '../components/button/button.html' 
      })   .state('components.checkbox', { 
       url: '/checkbox', 
       templateUrl: '../components/checkbox/checkbox.html' 
      }) 
      .state('components.forms', { 
       url: '/forms', 
       deepStateRedirect: true, 
       sticky: true, 
       views: { 
        '': { templateUrl: '..forms.html' }, 
        '[email protected]': { 
         templateUrl: '../components/forms/form-inline/forminline.html' 
        }, 
        '[email protected]': { 
         templateUrl: '../components/forms/form-default/formdefault.html' 
        }, 
        '[email protected]': { 
         templateUrl: '../components/forms/form-multicolumn/formmulticolumn.html' 
        } 
       }   
      }); 
      // use the HTML5 History API 
      $locationProvider.html5Mode({ 
       enabled: true, 
       requireBase: false 
      }); 
    }); 

    mendouiApp.controller('componentsController', ['$scope', '$state', 'sideNavService', function($scope, $state, sideNavService, COMPONENTS_LIST){ 
     $scope.componentsList = sideNavService.components; 
     $scope.componentsnav = COMPONENTS_LIST.children; 
     $scope.go = function(tab) { 
      $state.go(tab.name); 
     } 
    }]); 
    mendouiApp.controller('getStartedController', ['$scope', '$state', 'sideNavService', 'fixedSideNavService', function($scope, $state, sideNavService, fixedSideNavService){ 
     $scope.getstartedList = sideNavService.getstarted; 
    }]); 

    /*** This is for the external url reference ***/ 
    mendouiApp.run(function($rootScope, $state, $stateParams, $window, fixedSideNavService, copyToClipBoardService) { 
     $rootScope.$on('$stateChangeStart', 
      function(event, toState, toParams, fromState, fromParams, $state, $stateParams) { 
       if (toState.external) { 
        event.preventDefault(); 
        $window.open(toState.url, '_self'); 
       } 
     }); 
     $rootScope.$on('$viewContentLoaded', function(event){ 
      fixedSideNavService.fixedsidenav(); 
      copyToClipBoardService.copytoclipboard(); 
     }); 

     $rootScope.$state = $state; 
     $rootScope.$stateParams = $stateParams; 
     $state.transitionTo('home'); 
    }); 
    })(); 

service.js

angular.module('mendouiApp').service('sideNavService', function() { 
    return { 
    "getstarted" : [ 
     { 
      "name" : "Overview", 
      "link" : "home.overview" 
     } 
     { 
      "name" : "Summary", 
      "link" : "home.overview" 
     } 

    ], 
    "components" : [ 
     { 
      "name" : "Alerts", 
      "link" :"components.alert" 
     }, 
     { 
      "name" : "Button", 
      "link" :"components.button" 
     }, 
     { 
      "name" : "Button Groups", 
      "link" :"components.buttongroup" 
     }, 
     { 
      "name" : "Button Icons", 
      "link" :"components.buttonicons" 
     }, 
     { 
      "name" : "Checkbox", 
      "link" :"components.checkbox" 
     }, 
     { 
      "name" : "Datepicker", 
      "link" :"components.datepicker" 
     }, 
     { 
      "name" : "Forms", 
      "link" : "components.forms" 
     } 

    ] 
}; 
}); 
+0

問題是什麼?請清理一下,是一個完整的混亂,真的很難幫助你。 – Canastro

回答

1

你的問題是有點混亂,但經過一段時間與我玩能理解我做這個小提琴:http://jsfiddle.net/canastro/c4kt2myc/2/我希望它可以作爲您所期望。

着重談的主要問題是:

.state("root.components.button", { 
    url: '/components/button', 
    views: { 
     '[email protected]': { 
      template: ` 
       <div> 
        <a ui-sref="root.components.button.default">default</a> 
        <a ui-sref="root.components.button.disabled">disabled</a> 
        <div ui-view="buttonsContent"></div> 
       </div> 
      ` 
     } 
    } 
}) 
.state("root.components.button.default", { 
    url: '/components/button/default', 
    views: { 
     '[email protected]': { 
      template: 'root.components.button.default' 
     } 
    } 
}) 
.state("root.components.button.disabled", { 
    url: '/components/button/disabled', 
    views: { 
     '[email protected]': { 
      template: 'root.components.button.disabled' 
     } 
    } 
}) 

在第一級你有一個抽象的途徑,所以你總是可以有你的基本存在佈局。

然後在Started/Components路徑中,將內容加載到mainside ui-views中。

在所有Started和Component子路由中,您只需覆蓋main視圖。

最後,在最後一級,你需要說你想填充前一個狀態創建的UI視圖的內容,通過執行諸如[email protected]之類的操作。

+0

感謝您花時間幫助我。上面我貼的代碼也有點這樣做。但是,如果我卡住了主要和側面的UI視圖,現在用戶將點擊sidenav中的鏈接。例如「說複選框」。現在主要的ui-view被其內容所包含。此內容具有導航標籤,如(堆疊,禁用,..)默認情況下,第一個標籤內容應顯示在標籤下方的視圖中。點擊禁用後,uiview將隨其內容而改變。附加屏幕pdf – dragonfly

+0

更新了答案,我認爲它可能與您現在需要的相符 – Canastro