我試圖做使用離子與像這樣結構的混合應用:離子不同的標籤內容
#/app (sidemenu.html)
#/app/noTabContent1 (notab-content1.html)
#/app/noTabContent2 (notab-content2.html)
#/app/tab1 (tab1.html)
#/app/tab1/content1 (tab1-content1.html)
#/app/tab1/content2 (tab1-content2.html)
#/app/tab2 (tab2.html)
#/app/tab2/content1 (tab2-content1.html)
#/app/tab2/content2 (tab2-content2.html)
的問題是,它似乎像標籤頁之間的衝突。例如,如果我第一次訪問tab1
內容頁,那麼我稍後訪問tab2
內容頁時,它仍會顯示tab1
內容。如果我先訪問tab2
內容頁面,則無論我如何嘗試訪問tab1
內容頁面,它都將始終顯示tab2
內容。
這是爲什麼?我的構造錯了嗎?或者,它是離子蟲?我如何克服它?
編輯:這裏是爲了更容易理解我的例子代碼:
的index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<!-- ionic/angularjs js -->
<link href="http://code.ionicframework.com/1.1.0/css/ionic.css" rel="stylesheet">
<script src="http://code.ionicframework.com/1.1.0/js/ionic.bundle.js"></script>
<!-- your app's js -->
<!--<script src="js/app.js"></script>
<script src="js/controllers.js"></script>-->
</head>
<body ng-app="starter">
<ion-nav-view></ion-nav-view>
<!-- MENU Template -->
<script id="templates/menu.html" type="text/ng-template">
<ion-side-menus enable-menu-with-back-views="false">
<ion-side-menu-content>
<ion-nav-bar class="bar-stable">
<ion-nav-back-button>
</ion-nav-back-button>
<ion-nav-buttons side="left">
<button class="button button-icon button-clear ion-navicon" menu-toggle="left">
</button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-nav-view name="menuContent"></ion-nav-view>
</ion-side-menu-content>
<ion-side-menu side="left">
<ion-header-bar class="bar-stable">
<h1 class="title">Left</h1>
</ion-header-bar>
<ion-content>
<ion-list>
<ion-item menu-close href="#/app/content1">
Content 1
</ion-item>
<ion-item menu-close href="#/app/content2">
Content 2
</ion-item>
<ion-item menu-close href="#/app/tab/content1">
Tab 1 Content 1
</ion-item>
<ion-item menu-close href="#/app/tab/content2">
Tab 1 Content 2
</ion-item>
<ion-item menu-close href="#/app/tab2/content1">
Tab 2 Content 1
</ion-item>
<ion-item menu-close href="#/app/tab2/content2">
Tab 2 Content 2
</ion-item>
</ion-list>
</ion-content>
</ion-side-menu>
</ion-side-menus>
</script>
<!-- Tab1 Template -->
<script id="templates/tab1.html" type="text/ng-template">
<ion-tabs class="tabs-top tabs-color-active-positive">
<ion-tab title="Tab1 - Content1" icon-off="ion-ios-pulse" icon-on="ion-ios-pulse-strong" href="#/app/tab/content1">
<ion-nav-view name="tab-Content"></ion-nav-view>
</ion-tab>
<ion-tab title="Tab1 - Content2" icon-off="ion-ios-chatboxes-outline" icon-on="ion-ios-chatboxes" href="#/app/tab/content2">
<ion-nav-view name="tab-Content2"></ion-nav-view>
</ion-tab>
</ion-tabs>
</script>
<!-- Tab2 Template -->
<script id="templates/tab2.html" type="text/ng-template">
<ion-tabs class="tabs-top tabs-color-active-positive">
<ion-tab title="Tab2 - Content1" href="#/app/tab2/content1">
<ion-nav-view name="tab2-Content"></ion-nav-view>
</ion-tab>
<ion-tab title="Tab2 - Content2" href="#/app/tab2/content2">
<ion-nav-view name="tab2-Content2"></ion-nav-view>
</ion-tab>
</ion-tabs>
</script>
<!-- Content1 Template -->
<script id="templates/content1.html" type="text/ng-template">
<ion-view view-title="Content 1">
<ion-content>
<h1>Content 1</h1>
</ion-content>
</ion-view>
</script>
<!-- Content2 Template -->
<script id="templates/content2.html" type="text/ng-template">
<ion-view view-title="Content 2">
<ion-content>
<h1>Content 2</h1>
</ion-content>
</ion-view>
</script>
</body>
</html>
app.js
// Ionic Starter App
// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
angular.module('starter', ['ionic'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('app', {
url: '/app',
abstract: true,
templateUrl: 'templates/menu.html',
//controller: 'AppCtrl'
})
.state('app.tab', {
url: '/tab',
views:{
'menuContent':{
templateUrl: 'templates/tab1.html'
}
}
})
.state('app.tab2', {
url: '/tab2',
views:{
'menuContent':{
templateUrl: 'templates/tab2.html'
}
}
})
.state('app.content1', {
url: '/content1',
views: {
'menuContent': {
templateUrl: 'templates/content1.html'
}
}
})
.state('app.content2', {
url: '/content2',
views: {
'menuContent': {
templateUrl: 'templates/content2.html'
}
}
})
.state('app.tab.content1', {
url: '/content1',
views: {
'tab-Content': {
templateUrl: 'templates/content1.html'
}
}
})
.state('app.tab.content2', {
url: '/content2',
views: {
'tab-Content2': {
templateUrl: 'templates/content2.html'
}
}
})
.state('app.tab2.content1', {
url: '/content1',
views: {
'tab2-Content': {
templateUrl: 'templates/content1.html'
}
}
})
.state('app.tab2.content2', {
url: '/content2',
views: {
'tab2-Content2': {
templateUrl: 'templates/content2.html'
}
}
})
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/app/content1');
});
http://codepen.io/anon/pen/LpVVOr?editors=101
您需要提供導航代碼以瞭解發生了什麼問題。如果可能的話製作一個代碼簿。 –
@KaranKumar我在codepen中創建了一個示例代碼,以便於理解情況。請參考它。謝謝。 – user1995781
@KaranKumar如果您看不到問題,請在使用其中一個標籤頁進行測試時刷新頁面。任何想法如何解決它? – user1995781