books_ctrl.js.coffee
myApp.factory "Book", ($resource) ->
$resource("/books/:id", {id: "@id", page: 3})
上述工厂声明工作正常。现在为了让我的分页工作,我希望将$ scope中的值包含到$ resource-component中。有点像:
myApp.factory "Book", ($resource) ->
$resource("/books/:id", {id: "@id", page: $scope.currentPage})
但是会返回此错误:
ReferenceError: $scope is not defined
完整代码:books_ctrl.js.coffee
myApp.factory "Book", ($resource) ->
$resource("/books/:id", {id: "@id", page: $scope.currentPage}, {})
myApp.controller "BooksCtrl", ($http, $scope, Book) ->
$scope.init = () ->
$scope.currentPage = 1
$scope.getBooks()
$scope.getBooks = () ->
Book.query().$promise.then (books) ->
$scope.books = books
$scope.setPage = (newPage) ->
newPage = 1 if newPage < 1
$scope.currentPage = newPage
$scope.getBooks()