S
S
Sergey Vydayko2016-08-26 16:04:48
JavaScript
Sergey Vydayko, 2016-08-26 16:04:48

As when clicking on an element, record its data. AngularJS?

The essence of the question is this, there are posts that are displayed using ng-repeat, titles are displayed by id, i.e. post with id=1 title: 'first'
with id=2 title: 'second', etc. as when clicking on any of them, write down their id in order to display the same post on the other page that I clicked on.
This is how I list them initially, i.e. all posts
view

<div class="post">
  <p ng-repeat="post in $ctrl.posts">
  	<a href="#/open-post" style="color: #fff">{{post.title}}</a>
  </p>
 </div>

Angular
angular.
  module('listView').
  component('listView', {
    templateUrl: "app/list-view/list-view.template.html",
    controller: ['$http', 
      function listViewCtrl($http){
        var self = this;

        $http.get('http://tranquil-gorge-323326.herokuapp.com/api/posts').then(function(res){
          self.posts = res.data;
        });
      }
    ]
  });

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question