すべてのページについて質問がある$ scope.questionがあります。角度js:依存関係ルートを解決する
私はページワイズの質問をループしたいと思います。このために私は関数questionsCtrlを作成しました。この機能は、経路を設定するときにconfigで呼び出すことになっています。
ここでは定義されていません。
$ scope.questionsからページのデータを取得する方法をお勧めします。
app.js
(function() {
"use strict";
var app = angular.module("autoQuote",["ui.router","ngResource"]);
app.config(["$stateProvider","$urlRouterProvider", function($stateProvider,$urlRouterProvider){
$urlRouterProvider.otherwise("/");
$stateProvider
.state("step1", {
url : "",
controller: "questionsCtrl",
resolve: {
pageQuestion: $scope.questions
}
})
.state("step2", {
url : "/step2",
controller: "questionsCtrl",
})
}]
);
}());
questionCtrl.js
(function() {
"use strict";
angular
.module("autoQuote")
.controller("questionsCtrl",["$scope","$state","$q",questionsCtrl]);
function questionsCtrl($scope,$state,$q) {
console.log('here in get question for page: '+$state.current.name);
//var deferred = $q.defer();
if($state.current.name == "" || $state.current.name == "step1")
{
$scope.pageQuestion = $scope.RC1_Cars_v2;
}
else if($state.current.name == "step2")
{
$scope.pageQuestion = $scope.RC1_Drivers_v2;
}
//return deferred.promise;
console.log($scope);
}
}());
HTML
<div class="container-fluid col-md-8">
<div ng-controller="autoQuoteCtrl">
<div ng-repeat="que in pageQuestion">
<!-- pagequestion will be in loop here -->
</div>
</div>
</div>
は、ここでは、完全なコードのための私のplunker http://plnkr.co/edit/kLc6DPqzQgLNpUBaLtZi?p=previewです。
詳細な回答に感謝します。私はプランナーのapp.jsとquestionResource.jsを更新しました。しかし、エラーを取得します。 –
実際、Plunkerには多くのエラーがあります。どのようにあなたについてゼロから新しいPlunkerを作成し、あなたが本当にあなたのデータ、ルータconfiguraton、テンプレートとコントローラをフェッチするサービスを意味し、あなたの解決作業を取得する必要があるものだけを追加します。 – LordTribual