How to work with events in the Angular?

0

Look at the image;

ThisimageappearswhenthetextBoxisdifferentfromNULLasshownbelow;

But it should only appear when editing.

This is my component class responsible for this page;

export class BaseFormComponent implements OnInit {

  form: FormGroup;
  isInsertMode: boolean = true;
  private NEW = 'new';

  constructor(private _formBuilder: FormBuilder,
    public baseService: BaseService,
    private activatedRoute: ActivatedRoute, ) {
  }

  ngOnInit() {
    this.form = BaseForm.createForm(this._formBuilder);
    const { id } = this.activatedRoute.snapshot.params;
    this.isInsertMode = id === this.NEW;
    if (this.isInsertMode) {
      this.montaReferencia();

    }
  }

  private montaReferencia() {
    this.form.get('descricao').valueChanges.subscribe(descricao => {
      this.form.get('referencia').setValue(StringUtils.removeAccent(this.retiraEspacos(descricao)).toUpperCase());
    });

  }

  private retiraEspacos(value: string) {
    return value.replace(/[-\s]/g, '_');
  }

}

Please, what I need is to create a method that is placed inside this conditional below, that to be true it automatically calls that message;

if (this.isInsertMode) {
      this.montaReferencia();

    }
    
asked by anonymous 12.12.2018 / 11:46

0 answers