Uczę się AngularJS i mam mały problem. Oto mój kod:
Plik routingu
var myApp = angular.module('myApp', ["ngRoute"]) myApp.config(['$routeProvider', function ($routeProvider) { $routeProvider .when('/test', { templateUrl: '/event/example.html', controller: 'exampleController' }, null) .when('/list', { templateUrl: '/event/list.html', controller: 'exampleController' }, null) .when('/test-list', { templateUrl: '/test/list.html', controller: 'testController' }, null) .when('/test/:id', { templateUrl: '/test/details.html', controller: 'testController' }, null) } ]);
Controller
angular.module('myApp').controller('testController', function ($scope, $http, $routeParams) { $http.get('https://jsonplaceholder.typicode.com/posts').then(function (response) { $scope.posts = response.data; }); $scope.id = $routeParams.id; });
Plik details.html
plik list.html
Pobieram sobie dane z jsonplaceholder i listuję w pliku.html, tworzę url z id danego postu, teraz chciałbym pobrać ten jeden konkretny rekord. Wartość id pobieram sobie z $routeParams. Mój problem polega na tym, że nie wiem jak teraz po wejściu pod url test/1 pobrało mi z jsonplaceholder post o id np 1, url do pobrania szczegółów danego posta to jsonplaceholder.typicode.com/posts/1