私はMEANstackを使用しています。空のオブジェクトを返すシンプルなstateparamsは次のとおりです。コード:
route.js
var app = angular.module('mean-blog.home', [
'ui.router']);
app.configを(関数($ stateProvider、$ urlRouterProvider){$ stateProvider
.state('organizers', {
url: '/organizers',
templateUrl: '/home/templates/organizers.html',
controller: 'OrganizerCtrl'
})
.state('viewprofile', {
url: '/vieworganizer/:organizerid',
templateUrl: '/home/templates/viewprofile.html',
controller: 'viewProfileCtrl'
})
$urlRouterProvider.otherwise("/");
});
controller.js
.controller('viewProfileCtrl', function($scope, Users, $stateParams) {
console.log($stateParams) //returns empty object
})
見ますファイル
<p> {{organizer._id}}</p>
<a ui-sref="vieworganizer({organizerid:organizer._id})">
<i class="fa fa-edit"></i>Edit
</a>
このui-srefは私に次のエラーも表示しています。
Error: Could not resolve 'vieworganizer' from state ''
[email protected]://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.15/angular-ui-router.js:3140:17
[email protected]://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.15/angular-ui-router.js:3068:14
link/</transition<@https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.15/angular-ui-router.js:4181:13
f/l<@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:138:473
[email protected]://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:40:72
nf/n.defer/c<@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:44:155
私は直接URL
http://localhost:3000/vieworganizer/59b8c14ebed9a011bc5acb54
を開くと、それは空のstateparamsオブジェクトを返します。
私はこの問題の解決に手伝ってくれる誰でも!
あなたの状態は 'vieworganizer'ではなく' viewprofile'と呼ばれます –
あなたは$ stateParamsを注入しているようには見えません。 .controller( 'viewProfileCtrl'、 '' $ scope '、' Users '、' $ stateParams '、function($ scope、Users、$ stateParams){.... – rrd