如何在angular.js中清除html表单?

时间:2014-03-14 07:37:32

标签: javascript forms angularjs

我有一个添加产品表单。当用户提交它时,我想向他展示带有重置值的新添加产品表单。我怎么能实现这个是angularjs?

1 个答案:

答案 0 :(得分:4)

像这样。

HTML:

<form ng-submit="submit()">
  <input type="text" ng-model="product.name">
  <input type="submit" value="Submit">
</form>

控制器:

$scope.product = {
  name: 'My product'
};

$scope.submit = function() {
  // process the product data

  // Reset the product on the scope
  // which clears the form
  $scope.product = {};
}