EventEmiter暂停并重新启动

时间:2016-02-24 10:55:07

标签: dart angular angular2-forms

我有以下代码

html的

<input
    type = "text"
    #raceCtrl = "ngForm"
    [ngFormControl] = "raceForm.controls['raceCtrl']"
    [(ngModel)] = "race.race"
    (input) = "inputHandler()"
    (mousemove) = "inputHandler()"
    class = "mdl-textfield__input"
    id = "race">

<input
    type = "text"
    #ethnicGroupCtrl = "ngForm"
    [ngFormControl] = "raceForm.controls['ethnicGroupCtrl']"
    [(ngModel)] = "race.ethnicGroup"
    (input) = "inputHandler()"
    (mousemove) = "inputHandler()"
    class = "mdl-textfield__input"
    id = "ethnicGroup">

.dart

RaceComponent( FormBuilder fb, ModelService modelSrvc ) {
    raceForm = fb.group( {
      'raceCtrl': ['', CustomValidators.requiredNounValidator( 2 )],
      'ethnicGroupCtrl': ['', CustomValidators.optionalNounValidator( 2 )]
    } );

    _raceCtrl = raceForm.controls['raceCtrl'];
    race = modelSrvc.getRace( );
    inputHandler( );
  }

  void inputHandler( ) {
    if ( raceForm.valid &&
        !isEmpty( _raceCtrl.value ) ) {
      isFormValid = true;
    }
    else {
      isFormValid = false;
    }
    race.isValid = isFormValid;
  }

  onSubmit( ) {
    isSubmitted = true;
    if ( isFormValid ) {
      raceEmitter.emit( {'topic': topic, 'race': race} );
    }
    else {
      raceEmitter.emit( {'topic': topic, 'race': new Race( )} );
    }

    raceMap = new JsonObject.fromJsonString( encode( race ) );

表单按预期提交。但从那时起,流仍保持打开状态,即使ethinicGroup出错,错误也会由流传播到存储。是否可以根据表单的有效性暂停和取消暂停流,以防止错误的数据传播。

0 个答案:

没有答案