How to work with events at Angular?

Asked

Viewed 109 times

1

Watch the image;

inserir a descrição da imagem aqui

This image appears when the textbox is different from NULL as shown below;

inserir a descrição da imagem aqui

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 within that condition below, that by being true it automatically calls that message;

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

    }
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.