2017-02-05 6 views
2

私は2つのHTMLページを持っています。 1つはexam.htmlで、その他はresult.htmlです。 exam.htmlのコントローラExamCtrlの特定の状態では、を使用してresult.htmlにルーティングします。しかし、resultページでは、コントローラResultCtrlは設定ファイルに追加してもロードされていないようです。AngularJS別のコントローラと異なるページへのルーティング

角度設定ファイル:

angular.module('exam').config(['$stateProvider', 
    function ($stateProvider) { 
    // Exam state routing 
    $stateProvider 
     .state('exam', { 
     abstract: true, 
     url: '/exam', 
     template: '<ui-view/>' 
     }) 
     .state('exam.list', { 
     url: '', 
     templateUrl: 'modules/exam/client/views/exam.client.view.html', 
     controller: 'ExamCtrl' 
     }) 
     .state('/result', { 
     url: '/result', 
     templateUrl: 'modules/exam/client/views/exam-result.client.view.html', 
     contoller: 'ResultCtrl' 
     }); 
    } 
]); 

ExamCtrl:

angular 
.module('exam') 
.controller('ExamCtrl', ['$scope', '$stateParams', '$location', 'Authentication', '$http', 
    function ($scope, $stateParams, $location, Authentication, $http) { 


$scope.submitAnswer = function (selected) {   
     //some code 
     if (qtnCounter > 5) { 
     // loads the result page. 
     $location.path('/result'); 
     } else { 
     $scope.getQues(); 
     } 
    }; 
    } 
]); 

ResultCtrl:

angular 
.module('exam') 
.controller('ResultCtrl', ['$scope', '$stateParams', '$location', 'Authentication', '$http', 
    function ($scope, $stateParams, $location, Authentication, $http) { 

    console.log('ResultCtrl'); 

    } 
]); 

result.html:

<body ng-controller="ResultCtrl"> 
    <h1>Result page!</h1> 
</body> 

答えて

1

Insted of $location$stateを使用して、アプリ内の特定の状態に変更します。

は、コントローラに$stateを注入し、その後、コントローラ

angular 
.module('exam') 
.controller('ExamCtrl', ['$scope', '$state', 'Authentication', '$http', 
    function ($scope, $state, Authentication, $http) { 


$scope.submitAnswer = function (selected) {   
     //some code 
     if (qtnCounter > 5) { 
     // loads the result page. 
     $state.transitionTo('/result'); 
     } else { 
     $scope.getQues(); 
     } 
    }; 
    } 
]); 
+0

ああビューとセットアップをロードしますtransitionTo()を呼び出します。とった。どうもありがとう! –

+0

Np、ハッピーコーディング:) –

関連する問題