Angular / Ionic приложение показывает пустую страницу и без ошибок в консоли

0

Я пытаюсь заставить мое простое приложение работать. Я хотел отделить файлы контроллера, но я всегда получаю пустую страницу и никаких ошибок в консоли браузера. Структура проекта приложения:

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 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/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/app/controllers.js:

angular.module('testapp.controllers', []);

www/app/newListController.js:

angular.module('testapp.controllers')
  .controller('NewListCtrl', function($scope) {
    alert('aa'); // **its not being executed!!!**

  });

www/templates/main.html:

<!--
Create tabs with an icon and label, using the tabs-positive style.
Each tab 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/templates/new-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>

Любая идея, что я должен там исправить? Консоль ничего не отображает.

Теги:
ionic-framework

1 ответ

0

Проблема в том, что ui-router пытается перенаправить ваше приложение в /new_list. Но нет такого состояния с этим URL-адресом.

Чтобы исправить вашу проблему, измените строку $urlRouterProvider.otherwise('/new_list'); до $urlRouterProvider.otherwise('/tab/new_list'); внутри вашего приложения.

Посмотрите на документы ui-router:

При использовании маршрутизации url вместе с вложенными состояниями поведение по умолчанию заключается в том, чтобы дочерние состояния добавляли свой url к URL-адресам каждого из своих родительских состояний.

  • 0
    Почему «вкладки»? Я думаю, это должно быть 'tab / new_list' ... В любом случае, это не помогло
  • 0
    извините, вы правы ... это была опечатка ... я попытался воспроизвести ваш пример, и после того, как я изменил вышеуказанную строку, отобразился правильный вид. Пожалуйста, посмотрите на плунжер, который я сделал.

Ещё вопросы

Сообщество Overcoder
Наверх
Меню