如何使用Controller As语法在提交后重置表单

时间:2016-10-14 05:27:34

标签: javascript asp.net angularjs typescript

通过表单添加对象后,我想重置表单,以便用户可以添加另一个。我已经尝试了$ setPristine(),但无法弄清楚语法。截至目前,我刚刚将位置路径设置回同一页面,但这当然不会重置任何内容。还想知道$ setPristine是否是正确的方法。这是我的保存功能。

    export class AddCarController {
    public newCar;
    public save() {
        this.carService.save(this.newCar).then(() => { this.$location.path('/addCarPage') });
    }
    constructor(
        private carService: MyApp.Services.CarService,
        private $location: angular.ILocationService
    ) { }

}

1 个答案:

答案 0 :(得分:0)

角度您可以在仅在html 中创建模型,也可以在控制器或两个地方的中创建模型

  

如果您在html中创建了模型

$scope.newCar = {} //this will empty whole ui model object
  

如果您已在Javascript控制器中创建模型

$scope.newCar = new carModel() //this will create new car object with default values , if you have model in controller
  

导航回来 - 不推荐