0

我正在关注这个 angular-meteor 教程http://angular-meteor.com/tutorials/angular1/bind-one-object

我不确定我有什么问题,但这里是代码:

angular.module('socially').controller('PartyDetailsCtrl', function($scope, $stateParams, $meteor){
    $scope.party = $meteor.object(Parties, $stateParams.partyId, false);

    $scope.save = function() {
    $scope.party.save().then(function(numberOfDocs){
      console.log('save success doc affected ', numberOfDocs);
    }, function(error){
      console.log('save error', error);
    });
  };

  $scope.reset = function() {
    $scope.party.reset();
  };
});

这是html:

Here you will see the details of party:

<input type="text" ng-model="party.name">
<input type="text" ng-model="party.description">

<button ng-click="save()">Save</button>
<button ng-click="reset()">Reset form</button>
<button ui-sref="parties">Cancel</button>

保存按钮正常保存对象,但重置操作没有做任何事情,没有错误或任何事情。

4

1 回答 1

1

$scope.party.reset();不清除表单,而是将对象的当前值重置为存储在数据库中的值。例如,如果您修改Parties文档的属性并调用重置函数,则 Meteor 对象的客户端版本将重置为服务器版本。

阅读有关$meteor.object的更多信息。

于 2015-11-09T17:39:53.813 回答