我正在努力让我的简单应用运行起来。 我想分离控制器文件,但我总是得到空白页面,浏览器控制台没有错误。 应用项目结构:
www
- app
|-controllers
|--controllers.js
|--mainController.js
|--newListController.js
|-services
|--listService.js
|-app.js
|-index.html
-templates
|--main.html
|--new-list.html
我的 www / 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>
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- 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/app.js"></script>
<script src="app/controllers/controllers.js"></script>
<script src="app/controllers/newListController.js"></script>
<script src="app/services/listService.js"></script>
</head>
<body ng-app="testapp">
<!--
The nav bar that will be updated as we navigate between views.
-->
<ion-nav-bar class="bar-dark">
<ion-nav-back-button>
</ion-nav-back-button>
</ion-nav-bar>
<ion-nav-view></ion-nav-view>
</body>
</html>
WWW /应用/ app.js :
angular.module('testapp', ['ionic', 'testapp.controllers', 'testapp.services'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
});
})
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
// setup an abstract state for the tabs directive
.state('tab', {
url: '/tab',
abstract: true,
templateUrl: 'templates/main.html'
})
// Each tab has its own nav history stack:
.state('tab.new_list', {
url: '/new_list',
views: {
'tab-dash': {
templateUrl: 'templates/new-list.html',
controller: 'NewListCtrl'
}
}
});
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/new_list');
});
WWW /应用/ controllers.js :
angular.module('testapp.controllers', []);
WWW /应用/ newListController.js :
angular.module('testapp.controllers')
.controller('NewListCtrl', function($scope) {
alert('aa'); // **its not being executed!!!**
});
WWW /模板/ main.html中:
<!--
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-ios-pulse" icon-on="ion-ios-pulse-strong" href="#/tab/dash">
<ion-nav-view name="tab-dash"></ion-nav-view>
</ion-tab>
<!-- Chats Tab -->
<ion-tab title="Chats" icon-off="ion-ios-chatboxes-outline" icon-on="ion-ios-chatboxes" href="#/tab/chats">
<ion-nav-view name="tab-chats"></ion-nav-view>
</ion-tab>
<!-- Account Tab -->
<ion-tab title="Account" icon-off="ion-ios-gear-outline" icon-on="ion-ios-gear" href="#/tab/account">
<ion-nav-view name="tab-account"></ion-nav-view>
</ion-tab>
</ion-tabs>
WWW /模板/新list.html :
<ion-view view-title="Dashboard">
<ion-content class="padding">
<h2>Welcome to Ionic</h2>
<p>
This is the Ionic starter for tabs-based apps. For other starters and ready-made templates, check out the <a href="http://market.ionic.io/starters" target="_blank">Ionic Market</a>.
</p>
<p>
To edit the content of each tab, edit the corresponding template file in <code>www/templates/</code>. This template is <code>www/templates/tab-dash.html</code>
</p>
<p>
If you need help with your app, join the Ionic Community on the <a href="http://forum.ionicframework.com" target="_blank">Ionic Forum</a>. Make sure to <a href="http://twitter.com/ionicframework" target="_blank">follow us</a> on Twitter to get important updates and announcements for Ionic developers.
</p>
<p>
For help sending push notifications, join the <a href="https://apps.ionic.io/signup" target="_blank">Ionic Platform</a> and check out <a href="http://docs.ionic.io/docs/push-overview" target="_blank">Ionic Push</a>. We also have other services available.
</p>
</ion-content>
</ion-view>
知道我应该在那里修理什么?控制台没有显示任何内容。
答案 0 :(得分:0)
问题是ui-router尝试将您的应用重定向到 / new_list 。但是没有这个网址的状态。
要解决您的问题,请将您的app.js中的行$urlRouterProvider.otherwise('/new_list');
更改为$urlRouterProvider.otherwise('/tab/new_list');
。
将url路由与嵌套状态一起使用时的默认值 行为是为了让子状态将其网址附加到每个网址的网址上 其母国。