我第一次和Ionic合作,我有一点问题。我已经阅读了文档和教程,但我无法弄清楚我做错了什么。
首先,这是我的代码(我从一个空白项目开始)。
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() {
if(window.cordova && window.cordova.plugins.Keyboard) {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
// Don't remove this line unless you know what you are doing. It stops the viewport
// from snapping when text inputs are focused. Ionic handles this internally for
// a much nicer keyboard experience.
cordova.plugins.Keyboard.disableScroll(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider.state('home', {
url: '/',
views: {
templateUrl: 'templates/home.html'
}
})
$urlRouterProvider.otherwise('/');
});
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>
<!-- compiled css output -->
<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="js/app.js"></script>
</head>
<body ng-app="starter">
<ion-side-menus>
<ion-side-menu-content>
<ion-nav-bar class="bar-positive">
<ion-nav-back-button></ion-nav-back-button>
</ion-nav-bar>
</ion-side-menu-content>
<ion-side-menu side="left">
<ion-list>
<ion-item menu-close ui-sref="home">
Home
</ion-item>
</ion-list>
</ion-side-menu>
</ion-side-menus>
</body>
</html>
我的观点(在/www/templates/home.html
中):
<ion-view view-title="Home">
<ion-content>
<div>
<div>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Beatae inventore quod nihil quia, provident porro! Nulla ad libero deserunt, ullam soluta voluptates quidem dolore harum hic consequatur quas suscipit, ab.</div>
<div>Rerum, eum. Doloribus ullam voluptas repudiandae corrupti ipsa modi magnam, odit perferendis quam reprehenderit sapiente. Rerum impedit sequi voluptatibus porro ducimus dolor animi atque cupiditate similique praesentium. Beatae, suscipit, dolor.</div>
<div>Quasi natus cupiditate dignissimos non sed quaerat dolorem assumenda minima consectetur, quibusdam nostrum odio molestias voluptate eaque ut fugit atque quia totam laudantium? Repellendus ad, voluptatem itaque ut dolor placeat!</div>
<div>Quidem illo, molestias pariatur dolor laudantium et doloribus nostrum, hic quae consequuntur, nesciunt explicabo temporibus tempore possimus. Sint dolor, suscipit, iure, dolorem maiores veniam est cum eligendi iusto dolorum praesentium?</div>
<div>Dicta nihil amet, sapiente deserunt, facilis autem. Est debitis voluptate velit dicta explicabo alias culpa laborum nesciunt mollitia delectus, quos ut eius, itaque qui temporibus laudantium iusto reprehenderit omnis incidunt.</div>
</ion-content>
</ion-view>
好的,基本上,我只想拥有一个视图(稍后再添加一些其他视图)。此时,我的主视图应该在我提供应用程序时呈现,但标题(导航栏)和内容都显示为不。我尝试了很多东西(我的app.js中的语法,缓存等)。但没有任何作用。
你知道吗? :)谢谢!答案 0 :(得分:0)
下面我复制了你的代码并完成了这些更改:
// 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) {
console.log('run');
$ionicPlatform.ready(function() {
if (window.cordova && window.cordova.plugins.Keyboard) {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
// Don't remove this line unless you know what you are doing. It stops the viewport
// from snapping when text inputs are focused. Ionic handles this internally for
// a much nicer keyboard experience.
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
StatusBar.styleDefault();
}
});
})
.config(function($stateProvider, $urlRouterProvider) {
console.log('config');
$stateProvider.state('app', {
url: "/app",
abstract: true,
templateUrl: "menu.html",
controller: 'AppController'
})
.state('app.home', {
url: "/home",
views: {
'menuContent': {
templateUrl: "home.html"
}
}
});
$urlRouterProvider.otherwise('/app/home');
})
.controller('AppController', function($scope) {
console.log('AppController');
});
<!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>
<link href="http://code.ionicframework.com/nightly/css/ionic.css" rel="stylesheet">
<script src="http://code.ionicframework.com/nightly/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>
</head>
<body ng-app="starter">
<ion-nav-view></ion-nav-view>
<script id="menu.html" type="text/ng-template">
<ion-side-menus>
<ion-pane ion-side-menu-content>
<ion-nav-bar class="bar-positive">
<ion-nav-back-button class="button-clear"><i class="icon ion-chevron-left"></i> Back</ion-nav-back-button>
</ion-nav-bar>
<ion-nav-view name="menuContent" animation="slide-left-right"></ion-nav-view>
</ion-pane>
<ion-side-menu side="left">
<header class="bar bar-header bar-positive">
<h1 class="title">Left</h1>
</header>
<ion-content class="has-header">
<ion-list>
<ion-item nav-clear menu-close ui-sref="home">
Home
</ion-item>
</ion-list>
</ion-content>
</ion-side-menu>
</ion-side-menus>
</script>
<script id="home.html" type="text/ng-template">
<ion-view view-title="Home">
<ion-nav-buttons side="left">
<button menu-toggle="left" class="button button-icon icon ion-navicon"></button>
</ion-nav-buttons>
<ion-content>
<div>
<div>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Beatae inventore quod nihil quia, provident porro! Nulla ad libero deserunt, ullam soluta voluptates quidem dolore harum hic consequatur quas suscipit, ab.</div>
<div>Rerum, eum. Doloribus ullam voluptas repudiandae corrupti ipsa modi magnam, odit perferendis quam reprehenderit sapiente. Rerum impedit sequi voluptatibus porro ducimus dolor animi atque cupiditate similique praesentium. Beatae, suscipit, dolor.</div>
<div>Quasi natus cupiditate dignissimos non sed quaerat dolorem assumenda minima consectetur, quibusdam nostrum odio molestias voluptate eaque ut fugit atque quia totam laudantium? Repellendus ad, voluptatem itaque ut dolor placeat!</div>
<div>Quidem illo, molestias pariatur dolor laudantium et doloribus nostrum, hic quae consequuntur, nesciunt explicabo temporibus tempore possimus. Sint dolor, suscipit, iure, dolorem maiores veniam est cum eligendi iusto dolorum praesentium?</div>
<div>Dicta nihil amet, sapiente deserunt, facilis autem. Est debitis voluptate velit dicta explicabo alias culpa laborum nesciunt mollitia delectus, quos ut eius, itaque qui temporibus laudantium iusto reprehenderit omnis incidunt.</div>
</div>
</ion-content>
</ion-view>
</script>
</body>
</html>