9

可能有一种简单的方法可以做到这一点,但我似乎无法找到方法。

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

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

1 回答 1

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

应该这样做

于 2012-07-21T06:38:39.650 回答