如何使用路径变量而不是使用AngularJS $ resource的请求参数

时间:2012-07-21 05:12:19

标签: rest resources angularjs path-variables

这可能是一种简单的方法,但我似乎无法找到方法。

当我点击下面显示的删除按钮时,角度会点击以下网址:

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

如何让它通过路径变量而不是像这样的请求参数:

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

继承人我的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>

这是我的控制器:

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});
    }
}

1 个答案:

答案 0 :(得分:9)

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

应该这样做