0

I want to get object from database by ID. I succeed to get all of the objects, but I have trouble with sending id as parameter. Here is my HTML code for all of the items:

    <tbody>
        <tr ng-repeat='event in events'>
          <td>{{event.name}}</td>
          <td>{{event.date}}</td>
          <td>{{event.createdBy}}</td>
          <td><button role='button' class='btn' ng-click="editEvent(event)" data-toggle="modal" href="#editModal">Edit</button></td>
        </tr>
     </tbody>

And here is my JavaScript code:

    var app = angular.module('votr', ['ngResource', 'ngRoute']);

    app.config(function($routeProvider) {
      $routeProvider
        .when('/', {templateUrl: 'event-list.html', controller: 'EventListCtrl'})
    });

    app.factory('EventService', function($resource) {
      return $resource('/api/events/:id');
    });

    app.controller('EventListCtrl', function($scope, $location, EventService) {
      EventService.query(function(events){
          $scope.events = events;
      });
    }

1 Answer 1

1

To get object by id use the following:

EventService.get({id:your_id})

Also take look at documentation

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.