简体   繁体   中英

Multiple Angular-ui-router-tabs

I'm having issues with multiple views that each contains the bootstrap tabs.

On my work I have two ui-views that both contain BS tabs.

My first question is, let's say we'll load the home page, how to display the default tab for both BS tabs on each ui-views?

For a single default is easy by calling the specific state but this one is different.

I used the deepStateRedirect for a single default tab to go to the state but I do need both the BS tabs display their default tabs.

My next question is, since there are two ui-views, how can I not affect the display of other ui-view if I changed the other?

Codes:

home.html

..some codes here..
<div class="col-sm-9 npm tab-div">
    <div class="tab-container npm">
        <tabs data="tabDataContent" type="tabs"></tabs>
        <div class="tab-content npm">
            <div ui-view="contentView" class="viewDiv"></div>
        </div>
    </div>
</div>          
<div class="col-sm-3 npm report-div">
    <div class="tab-container npm">
        <tabs data="tabDataReport" type="tabs"></tabs>
        <div class="tab-content npm">
            <div ui-view="reportView" class="viewDiv"></div>
        </div>
    </div>
</div>
..some codes here..

home controller

..some codes here..
$scope.tabDataContent = [
  {
    heading: 'REPORT MAP',
    route:   'home.ReportMapTab'
  },
  {
    heading: 'UNITS',
    route:   'home.UnitsTab'
  }
];

$scope.tabDataReport = [
  {
    heading: 'INCOMING',
    route:   'home.ReportIncomingTab'
  },
  {
    heading: 'ONGOING',
    route:   'home.ReportOngoingTab'
  }
];
..some codes here..

routers.js

..some codes here..
.state('home',{
  url:'/home',
  templateUrl: 'views/home.html',
  controller: 'HomeController',
  deepStateRedirect: { default: { state: 'home.init' } }
})


.state('home.init',{
  url:'',
  views: {
    "contentView": { 
      templateUrl: 'views/homeTabs/reportMap.html',
      controller: 'HomeReportMapController' 
    },
    "reportView": { templateUrl: 'views/homeTabs/reportIncoming.html' }
  } 
})


.state('home.ReportMapTab',{
  url:'/reportMap',
  views: {
    "contentView": { 
      templateUrl: 'views/homeTabs/reportMap.html',
      controller: 'HomeReportMapController'
    }
  }
})


.state('home.UnitsTab',{
  url:'/units',
  views: {
    "contentView": { 
      templateUrl: 'views/homeTabs/units.html',
      controller: 'HomeUnitsController'
    }
  }
})


.state('home.ReportIncomingTab',{
  url:'',
  views: {
    "reportView": { 
      templateUrl: 'views/homeTabs/reportIncoming.html',
    }
  }
})


.state('home.ReportOngoingTab',{
  url:'',
  views: {
    "reportView": { 
      templateUrl: 'views/homeTabs/reportOngoing.html',
    }
  }
})
..some codes here..

I have found this link and described very nicely about how to load nested views and multiple views within page:

https://scotch.io/tutorials/angular-routing-using-ui-router

.state('home', {
    url: '/home',
    views: {

        // the main template will be placed here (relatively named)
        '': { templateUrl: 'home.tpl.html' },

        // the child views will be defined here (absolutely named)
        'columnOne@home': { 
           template: 'child1.tpl.html',
           controller: ''
         },

        // for column two, we'll define a separate controller 
        'columnTwo@home': { 
            templateUrl: 'child2.tpl.html',
            controller: ''
        }
    }

});

Index.html

<div ui-view></div><!-- parent view renders home.tpl.html-->

In home.tpl.html declare the chiled views you wanted display

<!-- chiled views -->
<div class="col-sm-6">
    <div ui-view="columnOne"></div>
</div>


<div class="col-sm-6">
    <div ui-view="columnTwo"></div>
</div>

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