【发布时间】:2016-07-12 01:43:24
【问题描述】:
作为 AngularJS 应用程序的一部分,我有以下状态:
.state('app.stages', {
url: '/stages',
views: {
'menuContent': {
templateUrl: 'templates/stages.html',
controller: 'StagesCtrl'
}
}
})
.state('app.stage', {
url: '/stages/:stageId',
views: {
'menuContent': {
templateUrl: 'templates/stage.html',
controller: 'StageCtrl'
}
}
关联的控制器是:
controller('StagesCtrl', function($scope,$http) {
$http.get("http://localhost/apistages")
.then(function(response) {
$scope.stages = response.data;
});
})
.controller('StageCtrl', function($scope, $http, $stateParams) {
$http({
method: 'GET',
url: 'http://localhost/apistage/',
params: {stageId: $stateParams.stageId}
}).then(function successCallback(response) {
$scope.stage = response.data;
}, function errorCallback(response) {
});
});
阶段列表运行良好,但阶段控制器中的查询尝试访问http://localhost/apistage/?stageId=43,导致 500(内部服务器错误)。
我需要使用的 URL 格式是 http://localhost/apistage/43 。如何调整查询以获取该 URL?
【问题讨论】:
标签: javascript angularjs asynchronous angularjs-http