我試圖設置我的第一個角度的應用程序,我遇到了與ui路由器的困難。在功能上,用戶填寫一份調查問卷,然後將其發送到一個頁面,其中包含調查結果。提交時,用戶的結果會保存到工廠,並且每次提交時都會增加一個ID。我似乎無法使用ui-router來解析該個性化頁面。從ResultsCtrlAngularjs ui路由器無法解析狀態'調查''結果/ 0'
routerApp.controller('FormCtrl', ['$scope', 'questions', 'users', 'results',
function($scope, questions, users, results){
$scope.responses = [];
$scope.results = [];
$scope.multChoice = [];
$scope.imageQuestions = [];
$scope.questions = questions.questions;
$scope.code = results.lastId;
results.results.push($scope.results);
results.lastId++;
console.log($scope.results);
users.create({responses: $scope.responses, results: $scope.results});
代碼:
相反,我得到這個錯誤:
Could not resolve 'results/0' from state 'survey'
代碼從FormCrtl
routerApp.controller('ResultsCtrl', ['$scope', '$stateParams', 'results', function($scope, $stateParams, results){
console.log('hello world');
}]);
代碼從UI路由器:
.state('results', {
url: '/results/{id:int}',
templateUrl: '../../views/results.html',
controller: 'ResultsCtrl',
resolve: {
post: ['$stateParams', 'results', function($stateParams, results) {
return results.results[id];
}]
}})
從調查HTML
代碼:從結果工廠
</div>
<label>Please confirm that you have answered all of the questions</label>
<button ng-click = 'addUser()' ui-sref = 'results/{{code}}'>Submit</button>
</form>
代碼:
routerApp.factory('results', [ function(){
var o = {
results: [],
lastId: 0
};
return o;
}]);
單擊按鈕時什麼也沒有發生? – WMios
什麼是控制檯打印? – WMios
正確,我在標題中得到錯誤 – Carriemf