for 2.service layers angular.module (' starter.services ', []) .service (' Tab1service ', function ($http) { this.getclassify = function () { return [ &NBSP ; {Name: ' Health information ', viewable:true, Url:domain + '/info/list ', Page:1, rows:20}, {Name: ' Health knowledge ', Viewable:false, Url:domain + '/lore/list ', Page:1, rows:20}, {name: ' Health quiz ', Viewable:false, Url:domain + '/ask/list ', Page:1, rows:20}, {Name: ' Healthy Books ', Viewable:false, Url:domain + '/book/list ', Page:1, rows:20} ] } this.getlist = function (URL, page, rows) { return $http. Post (URL, {page:page, rows:rows}) } });
3. Perfect the corresponding Tab1ctrl
.controller(‘Tab1Ctrl‘, function ($scope, Tab1Service, $ionicSlideBoxDelegate, $ionicTabsDelegate) { var items = Tab1Service.getClassify() $scope.slides = items; $scope.tabs = items; var slideIndex = 0; $scope.slideChanged = function (index) { $ionicTabsDelegate._instances[1].select(index); }; $scope.$on(‘$ionicView.afterEnter‘, function () { $ionicTabsDelegate._instances[1].select($ionicSlideBoxDelegate.currentIndex()); }); $scope.selectedTab = function (index) { //滑动的索引和速度 $ionicSlideBoxDelegate.slide(index) }})
4. Code Interpretation
The menu section above uses the tab build, the middle part of the list uses Slidebox, there is no nesting, just to do some processing at the time of their choice.
Tab1service: Use dependency injection to invoke the service layer to fetch data.
Slidechange:slidebox Select the tab corresponding to the index selected.
Selectedtab: When tab is selected, the corresponding Slidebox is selected.
Ionicview.afterenter: The first item of tab is selected by default when page loading is complete.
_INSTANCES[1]: Because two tab is used in the project
[Ionic Open source Project Tutorial]-3rd The implementation of the left and right sliding menus (using tabs and Slidebox)