2017-02-16 11 views
0

私はIonicとHTML/JSの新機能ですが、$ state.goで切り替えて4つのビューを持つ基本的なアプリケーションを開発しようとしています。最初のビューにはボタンがあり、クリックすると2番目の状態に切り替える必要がありますが、そうではありません。これを修正する方法の提案は非常に高く評価されています。

私のapp.jsとindex.htmlは以下のとおりです。

// 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' 
 
var quiz = 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('index', { 
 
     url: '/', 
 
     abstract: true, 
 
     templateUrl: 'index.html' 
 
    }) 
 
    .state('page1', { 
 
     url: "/page1", 
 
     params: { 
 
     'imageQuestionAnswer':null, 
 
     'textQuestionAnswer':null 
 
     }, 
 
     controller: 'page1Ctrl' 
 
    }) 
 
    .state('imageQuestion', { 
 
     url: "/imageQuestion", 
 
     params: { 
 
     'imageQuestionAnswer':null, 
 
     'textQuestionAnswer':null 
 
     }, 
 
     controller: 'pictureQCtrl' 
 
    }) 
 
    .state('textQuestion', { 
 
     url: "/textQuestion", 
 
     params: { 
 
     'imageQuestionAnswer':null, 
 
     'textQuestionAnswer':null 
 
     }, 
 
     controller: 'textQCtrl' 
 
    }) 
 
    .state('result', { 
 
     url: "/result", 
 
     params: { 
 
     'imageQuestionAnswer':null, 
 
     'textQuestionAnswer':null 
 
     }, 
 
     controller: 'resultCtrl' 
 
    }) 
 
}) 
 

 
    $urlRouterProvider.otherwise("index.html") 
 

 

 
quiz.controller("page1Ctrl", function($scope, $ionicModal, $ionicLoading, $state) { 
 

 
    $scope.onStart = function() { 
 
    $state.go("imageQuestion", { 
 
     'imageQuestionAnswer':null, 
 
     'textQuestionAnswer':null 
 
    }) 
 
    } 
 

 
}) 
 

 
quiz.controller("pictureQCtrl", function($scope, $ionicModal, $ionicLoading, $state) { 
 

 
}) 
 

 
quiz.controller("textQCtrl", function($scope, $ionicModal, $ionicLoading, $state) { 
 

 
}) 
 

 
quiz.controller("resultCtrl", function($scope, $ionicModal, $ionicLoading, $state) { 
 

 
})
<!DOCTYPE html> 
 
<html ng-app='quiz'> 
 
    <head> 
 
    <meta charset="utf-8"> 
 
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> 
 
    <title>Welcome to my quiz app!</title> 
 

 
    <link rel="manifest" href="manifest.json"> 
 

 
    <!-- un-comment this code to enable service worker 
 
    <script> 
 
     if ('serviceWorker' in navigator) { 
 
     navigator.serviceWorker.register('service-worker.js') 
 
      .then(() => console.log('service worker installed')) 
 
      .catch(err => console.log('Error', err)); 
 
     } 
 
    </script>--> 
 

 
    <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="js/app.js"></script> 
 
    </head> 
 

 
    <body> 
 
    <ion-nav-bar class="bar-positive"> 
 
    <ion-nav-back-button> 
 
    </ion-nav-back-button> 
 
    </ion-nav-bar> 
 

 

 
    <ion-nav-view></ion-nav-view> 
 

 

 
    <ion-content> 
 
    <ion-view view-title="Welcome!"> 
 
    <ion-content class = "padding"> 
 
     <div> 
 
     <button class = "button button-royal" ng-click = "onStart()">Start</button> 
 
     </div> 
 
    </ion-content> 
 
    </ion-view> 
 
    </ion-content> 
 

 
    <script id = "imageQuestion" type="text/ng-template"> 
 
    <div> 
 
    Question 2! 
 
    </div> 
 
    </script> 
 
    </body> 
 
</html>

答えて

1

あなたはをonSubmit()関数を呼び出しているが、コントローラであなたは、関数名$ scope.onStartを宣言しました。関数名を変更すると動作します。

+0

私はこの修正を行い、上記のコードを編集しましたが、それでも同じ問題があります。 – Walter

+0

あなたは別の間違いを犯しました。あなたはあなたのモジュールをapp.js内の '初心者'として定義しており、未知のモジュール 'quiz'をindex.htmlに注入しています。 変化このライン 'VARクイズ= angular.module( 'スターター'、[ 'イオン'])' に 'VARクイズ= angular.module( 'クイズ'、[ 'イオン'])' –

+0

あなたがすべきまたあなたの経路を修正し、htmlはindex.htmlに含まれてはいけません。コントローラごとに別々のビューを作成します。イオンアプリの基礎を学ぶには、ドキュメンテーション/チュートリアルを参照してください。 –

関連する問題