在Angular中提交时重置formControl字段

时间:2019-04-10 15:31:06

标签: angular

我有一个onSubmit应该重置特定表单字段值的表单。到目前为止,我已经尝试了以下方法:

Ts文件:

ngOnInit() {
    this.loading = true;
    this.getIncident();
    this.loading = true;
      })
      this.addCommentsForm = new FormGroup({
        comment: new FormControl(''),
        number: new FormControl('')
      })
    }

onSubmit() {

      let putData = Object.assign({}, this.addCommentsForm.value);
      console.log('form, ', putData)
      this.uploading = true;
      this.commentProgress.progress = 100;
      this.service.putIncidentsComments(putData, this.s_id).subscribe((response: any) => {
        console.log("comment sent");
        this.getIncidentComments();
        this.uploading = false;
        this.commentProgress.progress = 0;
        this.addCommentsForm.reset();
      }, (errorResponse: any) => {
        console.log(errorResponse); //On unsuccessful response
        this.error = true;
        this.uploading = false;
      });
    }
  }

该行:this.addCommentsForm.reset();重设整个表单,我只想重设注释字段?有什么想法吗?

1 个答案:

答案 0 :(得分:1)

您可以获取from flask_socketio import SocketIO import socketio socketio_server = SocketIO(app, async_mode='gevent', engineio_logger=False) ####PART OF THE CODE THAT I TRIED TO ADD THE COMMUNICATION AS A CLIENT### ##Connecting to server as a client sio = socketio.Client() # !!! at this point i receive a new connection on remote server, however the code freezes on this line and the script hang on until the end of the connection sio = socketio.Connect(host, port) #i want to send data to a specific namespace sio.emit('remote-client', {'foo':'bar'}) ######################################################################## # Serve React App @app.route('/', defaults={'path': ''}) @app.route('/<path:path>') def serve(path): if path != "" and os.path.exists("static" + path): return send_from_directory('static', path) else: return send_from_directory('static', 'index.html') #---------------------Web Sockets-----------------------------# @socketio_server.on('connect', namespace='/test') def test_connect(): print 'Client Connected' @socketio_server.on('disconnect', namespace='/test') def test_disconnect(): print 'Client disconnected' if __name__ == '__main__': print "Starting Server..." socketio_server.run(app, debug=False) os.kill(os.getpid(), signal.SIGTERM) 并将其重置:

formControl