私は AngularJS を使い始めており、ルート パラメーターのプロパティにアクセスしているこのコードを表示したいと思います。
angular.module('messagecat', []).
config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/messages', {templateUrl: '/bundles/acmestore/js/partials/messages-list.html', controller: MessagesListCtrl}).
when('/messages/:messageId', {templateUrl: '/bundles/acmestore/js/partials/message-detail.html', controller: MessageDetailCtrl}).
otherwise({redirectTo: '/messages'});
}]);
/*controller*/
function MessagesListCtrl($scope, $http) {
$http.get('/messages').success(function(data) {
$scope.messages = data;
});
}
/* Does this following bit seem reasonable to you?*/
function MessageDetailCtrl($scope, $routeParams, $http) {
$http.get('/messages').success(function(data) {
$scope.messages = data[$routeParams.messageId];
//console.log($scope.messages);
});
}
the json model:
[
{
"id": 1,
"iam": 1,
"youare": 2,
"lat": 50.8275853,
"lng": 4.3809764,
"msgbody": "Lorem ipsum lorem ipsum lorem ipsum"
}
]