【发布时间】:2015-02-22 12:54:19
【问题描述】:
我已经启动了一个 Ionic Tabs 项目。现在我有一个按钮“initiateProcess”,我用ng-click 调用它并在控制器中执行一些操作,然后通过state.go 或state.transitionTo 进入某个状态(tab.target)完成它。
但是,当我不在 tabs.html 中包含该状态时,将不会加载该状态。当我确实包含它时, state.go 工作正常。此状态是独立的(可以视为子状态,但本身不是),我不希望它显示在我的标签中。
发生了什么事?
tabs.html(不带tab.target)
<!--
Create tabs with an icon and label, using the tabs-positive style.
Each tab's child <ion-nav-view> directive will have its own
navigation history that also transitions its views in and out.
-->
<ion-tabs class="tabs-icon-top tabs-color-active-positive">
<!-- Dashboard Tab -->
<ion-tab title="Status" icon-off="ion-ios7-pulse" icon-on="ion-ios7-pulse-strong" href="#/tab/dash">
<ion-nav-view name="tab-dash"></ion-nav-view>
</ion-tab>
// when I include here Target Tab with <ion-nav-view name = "tab.target" ... then it works
<!-- Account Tab -->
<ion-tab title="Account" icon-off="ion-ios7-gear-outline" icon-on="ion-ios7-gear" href="#/tab/account">
<ion-nav-view name="tab-account"></ion-nav-view>
</ion-tab>
</ion-tabs>
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'
// 'starter.services' is found in services.js
// 'starter.controllers' is found in controllers.js
angular.module('starter', ['ionic', 'ngCordova', 'ionic.utils', 'starter.controllers', 'starter.controllers-cloaking', 'starter.services'])
.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);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
});
})
.config(function($stateProvider, $urlRouterProvider) {
// Ionic uses AngularUI Router which uses the concept of states
// Learn more here: https://github.com/angular-ui/ui-router
// Set up the various states which the app can be in.
// Each state's controller can be found in controllers.js
$stateProvider
// setup an abstract state for the tabs directive
.state('tab', {
url: "/tab",
abstract: true,
templateUrl: "templates/tabs.html"
})
// Each tab has its own nav history stack:
.state('tab.dash', {
url: '/dash',
views: {
'tab-dash': {
templateUrl: 'templates/tab-dash.html',
controller: 'DashCtrl'
}
}
})
.state('tab.target', {
url: '/target',
views: {
'tab-target': {
templateUrl: 'templates/tab-target.html',
controller: 'TargetCtrl'
}
}
})
.state('tab.account', {
url: '/account',
views: {
'tab-account': {
templateUrl: 'templates/tab-account.html',
controller: 'AccountCtrl'
}
}
});
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/tab/dash');
});
DashController 中的函数($state 已注入)
$scope.initiateProcess = function() {
// some stuff
$state.go('tab.target')
}
tab-dash.html 中的按钮
<button class="button button-balanced" ng-click="initiateProcess()">
Go to Target
</button>
【问题讨论】:
-
你能检查你的控制台看它是否抛出任何错误或警告吗?
-
没有错误或警告......
-
检查您的错误。通常有一个列表列出您的文件名及其错误。您可以像这样忽略默认的离子错误:(localhost:8100/lib/ionic/js/ionic.bundle.js:7888:12)。
-
我没有看到任何错误。问题是只要我在 tabs.html 中包含 ion-nav-view name="tab.target" 它就可以工作
-
好吧,离子中的标签需要名称。它与您的 app.js 中的视图名称匹配......让我输入正确的格式
标签: javascript angularjs ionic-framework