从使用ngRoute到ui.Router($ stateProvider而不是$ routeProvider),所以我不确定我是否正在重构...尝试使用$ routeParams访问对象详细信息以获取ID。我正在使用ui-sref来获取ID客户端,但我不确定如何使用$ http呈现数据。
这就是我获取参数的方法:
<h4 class="inline-header">Topic Name:</h4>
<span> <a ui-sref="listing-detail({listingId:listing._id})">{{listing.topic}}</a></span>
来自我的控制器..
angular
.module('identifly', [
'ui.router',
'satellizer'
])
configRoutes.$inject = ["$stateProvider", "$urlRouterProvider",
"$locationProvider"]; // minification protection
function configRoutes($stateProvider, $urlRouterProvider,
$locationProvider) {
$stateProvider
.state('listing-detail', {
url: '/listing/:listingId',
templateUrl: 'templates/listing-show.html',
controller: 'ListingShowController',
controllerAs: 'listingShowCtrl'
});
点击此控制器...
ListingShowController.$inject = ['$http', '$routeParams'];
function ListingShowController ($http, $routeParams) {
var vm = this;
$http({
method: 'GET',
url: '/api/listings/'+$routeParams.id
}).then(function successCallback(json) {
vm.listing = json.data;
}, function errorCallback(response) {
console.log('There was an error getting the data', response);
});
};
收到此错误: https://docs.angularjs.org/error/ $注射器/ unpr?P0 = $ routeParamsProvider%20%3 C-%20 $ routeParams%20%3 C-%20ListingShowController