gpt4 book ai didi

javascript - Angularjs ui-router 无法从状态 'results/0' 解析 'survey'

转载 作者:行者123 更新时间:2023-11-27 23:56:35 24 4
gpt4 key购买 nike

我正在尝试设置我的第一个 Angular 应用程序,但我在 ui-router 方面遇到了困难。从功能上来说,用户填写一份调查,然后被发送到一个包含该调查的个人结果的页面。提交时,用户的结果将与每次提交时递增的 id 一起保存到工厂中。我似乎无法让 ui-router 解析到该个性化页面。

相反,我收到此错误:

Could not resolve 'results/0' from state 'survey'

来自 FormCrtl 的代码:

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});

来自 ResultsCtrl 的代码:

routerApp.controller('ResultsCtrl', ['$scope', '$stateParams', 'results', function($scope, $stateParams, results){
console.log('hello world');
}]);

来自 ui-router 的代码:

.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;
}]);

最佳答案

您在 ui-sref 指令中使用了错误的状态名称,这会导致您收到错误。 ui-sref 指令确实接受 stateName 并通过注册的状态搜索它。

ui-sref = 'results({id: code})'

关于javascript - Angularjs ui-router 无法从状态 'results/0' 解析 'survey',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32212537/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com