문제

There is probably an easy way to do this but I can't seem to find out how.

When I click on my delete button shown below angular hits the following url:

http://localhost:8080/rest/managedCourse?id=3

How can I get it to hit pass a path variable instead of a request parameter like this:

http://localhost:8080/rest/managedCourse/3

Heres my html:

<table>
    <tr ng-repeat="course in page.content">
        <td>{{course.title}}</td>
        <td>{{course.description}}</td>
        <td>{{course.creditValue}}</td>
        <td><button ng-click="remove(course.id)">Delete</button></td>
    </tr>
</table>

And here is my controller:

function ManagedCourseController($scope, $resource) 
{
    var ManagedCourse = $resource("rest/managedCourse/:courseId", {courseId:'@id'});

    $scope.page = ManagedCourse.getPage({"page.page": "0", "page.size": "3", "page.sort": "title", "page.sort.dir": "asc"});


    $scope.create = function (managedCourse) {
        ManagedCourse.create(managedCourse);
    }

    $scope.remove = function (courseId) {
        ManagedCourse.remove({id:courseId});
    }
}
도움이 되었습니까?

해결책

function ManagedCourseController($scope, $resource) 
{
    var ManagedCourse = $resource("rest/managedCourse/:courseId/:id", 
       {courseId:'@id'});
    ...

should do it

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top