2014-07-04 53 views
0

如何使用Restangular保存新对象? 当我在客户对象上执行save()时,出现此错误。任何想法为什么?使用Restangular保存对象的问题

saving "customer name" customers.js?body=1:14 
TypeError: undefined is not a function 

HTML

<form ng-submit="save(customer)"> 
    <input type="text" ng-model="customer.name"> 

控制器(CoffeeScript的)

$scope.save = (customer) -> 
    console.log("saving '#{customer.name}'") # this works 
    customer.save() 

回答

0

我计算出来。这工作。 :-)

1 angular 
2 .module('app') 
3 .controller "CustomersCtrl", ($scope, Restangular) -> 
4 
5  # Initalize the Customer object 
6  Customer = Restangular.all('customers'); 
7 
8  $scope.getCustomers =() -> 
9  Customer.getList().then (customers) -> 
10   $scope.customers = customers 
11 
12  $scope.save = (customer) -> 
13  Customer.post(customer)