Note that there are some explanatory texts on larger screens.

plurals
  1. POBest way to get data, display it in a list and linking each item to a detail page
    primarykey
    data
    text
    <p>I'm doing a project with angularjs and have a bit of trouble figuring out some things. So basically I'm getting a .json via an api which contains some university courses. I like to display them and when I click on one of them the detail page should be displayed.</p> <pre><code>function getcourses($scope, $http, $location, $rootScope){ $scope.init = function (){ $scope.apiroot = "http://...."; $http.get($scope.apiroot + 'courses.json').then(function(response){ $scope.courses = response.data.courses; }) }; $scope.selectCourse = function (index) { $scope.detailcourse = $scope.courses[index]; $location.path('/course'); }; } </code></pre> <p>courses.html:</p> <pre><code>&lt;table ng-controller="getcourses" data-ng-init="init()"&gt; ... &lt;li ng-repeat="course in courses"&gt; &lt;a ng-click="selectCourse($index)" ng-href=""&gt;{{course.title}}&lt;/a&gt; &lt;/li&gt; </code></pre> <p>course.html:</p> <pre><code>&lt;div class="panel panel-small" ng-controller="getcourses"&gt; &lt;div class="panel-heading"&gt;{{detailcourse.title}}: {{detailcourse.subtitle}}&lt;/div&gt; &lt;div class="list-group"&gt; &lt;class="list-group-item"&gt;{{detailcourse.description}}&lt;/class&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>This way, when I click on a link and get redirected nothing is shown. I guess because it gets all the courses again as soon as the other page gets loaded? I got it working with a rootScope but I think that's not very pretty. So what's the best way to do something like this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload