角反应形式克隆值

时间:2019-08-20 19:17:53

标签: javascript angular forms angular-reactive-forms

我正在使用Angular Reactive Form作为注册表单。

*** Settings ***
Documentation     This is a simple test with Robot Framework
Library           SeleniumLibrary

*** Variables ***
${SERVER}         http://www.google.com
${BROWSER}        chrome
${DELAY}          0

*** Keywords ***
Open Browser To Login Page
    Open Browser    ${SERVER}    ${BROWSER}
    S
    Maximize Browser Window
    Set Selenium Speed    ${DELAY}

在这种形式下,我希望当用户在app = Flask(__name__) FLASKR_SETTINGS = 'config.ProductionConfig' app.config.from_object(FLASKR_SETTINGS) app.config.update(DEBUG=True, MAIL_DEBUG=True, MAIL_SERVER ='smtp.gmail.com', MAIL_PORT=465, MAIL_USE_SSL=True, MAIL_USE_TLS=False, MAIL_FAIL_SILENTLY=False, MAIL_SUPPRESS_SEND = False, TESTING = False) @app.route('/send-mail') def send_mail(): subjet = 'Test email' sender = 'mailreport@gmail.com' recipients = ['errorMail@gmail.XXX'] msg = Message( subjet, sender=sender, #sender=('Testy McTesterson', sender), extra_headers={'Disposition-Notification-To': sender}, recipients=recipients ) env = Environment(loader=PackageLoader('app', 'templates')) template = env.get_template('mytemplate.html') msg.body = template.render(name='data') try: mail.send(msg) except Exception as error: return str(error) return "ok" 字段中输入类似值时,会自动填充到 this.personalDataForm = new FormGroup({ 'name': new FormControl(null, Validators.required), 'username': new FormControl(null, Validators.required), 'address': new FormControl(null, Validators.required), 'email': new FormControl(null, [Validators.required, Validators.email]), 'mobile': new FormControl(null), 'password': new FormControl(null), }); 字段中

但是,当用户在name字段中键入内容时,username字段不会受到影响。

请让我知道如何使用反应式表单来实现此目的。

2 个答案:

答案 0 :(得分:3)

将所有表单操作逻辑都放在一个地方(在TS文件中),这是使用Reactive Forms后的推荐方法。

尝试一下:

try { 
    query = null; 
    loadSqlScript("create_table_foo.sql"); 
    preparedStatement = connection.prepareStatement(query);    
    preparedStatement.execute(); } 
catch......

要取消订阅valueChanges,请检查以下答案:https://stackoverflow.com/a/46893278/2050306

工作stackblitz

答案 1 :(得分:1)

您可以在<div><span>H<sub>2</sub>O is good</span></div>上使用模板变量,如下所示(最简单的方法):

username

<input type="text" formControlName="name" #nameTemplate /> <input type="text" formControlName="username" [value]="nameTemplate.value"/> 字段中键入的任何内容都会反映在name字段中,反之亦然。并且该表单将保留username的值。