我是 AngularJS 和 Ionic 的新手。
我正在创建一个在其中一个菜单选项中同时包含 sidemenu 和标签的应用。标签应使用nested view
呈现其内容,因此此处不需要HTML
。
我可以在sidemenu选项和所有作品之间导航并正确呈现。当我进入托管选项卡的菜单选项时,问题就出现了。
虽然标签导航面板正确呈现并且我可以在标签之间导航,但标签的内容会以某种方式创建,但仍然是不可见。如果我执行了ionic serve
并使用HTML
或类似内容检查生成的Firebug
,我可以看到生成的nested view
的内容。我只是在浏览器上看不到它。我Chromium
和Firefox
都会遇到这种情况,因此浏览器不应该是问题所在。尝试使用Android
模拟器时会发生同样的情况。
我首先想到了一个routing
问题,但这对我来说没有多大意义,因为内容是生成的(只是不可见)。
我创建了一个Plunkr,我的代码减少到最小,以便重现问题。无论如何,我的(相关)代码如下:
的index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width" name="viewport" />
<title></title>
<link rel="stylesheet" type="text/css" href="http://code.ionicframework.com/nightly/css/ionic.css">
<link href="app.css" rel="stylesheet">
<script src="http://code.ionicframework.com/nightly/js/ionic.bundle.js"></script>
<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="app.js"></script>
<script src="services.js"></script>
<script src="controllers.js"></script>
</head>
<body ng-app="starter">
<ion-nav-view></ion-nav-view>
</body>
</html>
app.js
angular.module('starter', ['ionic', 'starter.controllers'])
.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) {
$stateProvider
.state('app', {
url: "/app",
abstract: true,
templateUrl: "menu.html",
controller: 'AppCtrl'
})
.state('app.questionsAnswers', {
url: "/questionsAnswers",
// abstract: true,
views: {
'menuContent': {
templateUrl: "questionsAnswers.html"//,
// controller: 'questionsAnswersCtrl'
}
}
})
.state('app.questionsAnswers.recent', {
url: "/recent",
views: {
'recent-questions': {
templateUrl: "recentQuestionsAnswers.html",
controller: 'recentQuestionsAnswersCtrl'
}
}
})
.state('app.questionsAnswers.mostVoted', {
url: "/mostVoted",
views: {
'most-voted-questions': {
templateUrl: "mostVotedQuestionsAnswers.html",
controller: 'mostVotedQuestionsAnswersCtrl'
}
}
})
.state('app.questionsAnswers.random', {
url: "/random",
views: {
'random-questions': {
templateUrl: "randomQuestionsAnswers.html",
controller: 'randomQuestionsAnswersCtrl'
}
}
})
.state('app.foo', {
url: "/foo",
views: {
'menuContent': {
templateUrl: "foo.html",
controller: 'fooCtrl'
}
}
});
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/app/foo');
});
menu.html
<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">Menu</h1>
</ion-header-bar>
<ion-content>
<ion-list>
<ion-item nav-clear menu-close href="#/app/questionsAnswers">
Questions & Answers
</ion-item>
<ion-item nav-clear menu-close href="#/app/foo">
Foo
</ion-item>
</ion-list>
</ion-content>
</ion-side-menu>
</ion-side-menus>
questionsAnswers.html
<ion-view view-title="Questions & Answers">
<ion-content>
<h1>Questions & Answers</h1>
<ion-tabs class="tabs-positive tabs-icon-only">
<ion-tab title="Recent" ui-sref="app.questionsAnswers.recent" icon-on="ion-ios-clock" icon-off="ion-ios-clock-outline">
<ion-nav-view name="recent-questions"></ion-nav-view>
</ion-tab>
<ion-tab title="Most voted" ui-sref="app.questionsAnswers.mostVoted" icon-on="ion-arrow-up-c" icon-off="ion-arrow-up-a">
<ion-nav-view name="most-voted-questions"></ion-nav-view>
</ion-tab>
<ion-tab title="Random" ui-sref="app.questionsAnswers.random" icon-on="ion-help-circled" icon-off="ion-help">
<ion-nav-view name="random-questions"></ion-nav-view>
</ion-tab>
</ion-tabs>
</ion-content>
</ion-view>
我的SSCCE中的其余HTML
个文件只是该类型的简单视图:
<ion-view view-title="foo">
<ion-content>
<ion-list>
foo content
</ion-list>
</ion-content>
</ion-view>
controllers.js
在示例中并不真正相关,因为所有控制器基本上都没有(当然在真实应用程序中它们都有自己的功能)。
我已经在SO和其他网站上阅读了很多问题和答案,但似乎无法找到我做错的事情。问题是:为什么我的标签中的嵌套视图会呈现但仍然不可见?
答案 0 :(得分:4)
您的ion-view
问题&amp;答案( questionAnswers.html )不能包含<ion-content>
元素,因为您已在每个子视图中设置<ion-content>
。
EX:
<ion-view view-title="Most voted questions and answers">
<ion-content>
<h1>Most voted Questions</h1>
</ion-content>
</ion-view>
所以 questionAnswers.html 应该是:
<ion-view view-title="Questions & Answers">
<ion-tabs class="tabs-positive tabs-icon-only tabs-top">
<ion-tab title="Recent" ui-sref="app.questionsAnswers.recent" icon-on="ion-ios-clock" icon-off="ion-ios-clock-outline">
<ion-nav-view name="recent-questions">
</ion-nav-view>
</ion-tab>
<ion-tab title="Most voted" ui-sref="app.questionsAnswers.mostVoted" icon-on="ion-arrow-up-c" icon-off="ion-arrow-up-a">
<ion-nav-view name="most-voted-questions"></ion-nav-view>
</ion-tab>
<ion-tab title="Random" ui-sref="app.questionsAnswers.random" icon-on="ion-help-circled" icon-off="ion-help">
<ion-nav-view name="random-questions"></ion-nav-view>
</ion-tab>
</ion-tabs>
</ion-view>
这是plunker。