Call a method in Angular 6

1

I'm starting with Angular 6, I need to call a method in HTML but I do not know how to do it. The only way I have found is to assign it to an event but what I want is for the method to be executed only without the need to click on a button or something similar. How do I invoke the method in the html?

    
asked by JulianProg 09.09.2018 в 23:55
source

1 answer

0

You can make use of a life cycle hook, which is invoked after Angular has initialized all the properties of a data-bound policy. Define a ngOnInit() as a method to handle any additional initialization tasks.

This helps you to execute important functions or methods that are required when starting a component in Angular.

Source: Angular.io

Example

  ngOnInit()
  {
    //Declaracion de variables para activar clases nativas de Bootstrap = Active.
    this.claseInventario='nav-link active';
    //Declaración de variables del titulo de cada componente
    this.tituloComponente = 'Inventario';

    //Evalumos formulario
    this.evaluated = true;
    //Iniciamos el validador cuando inicie el controlador del componente
    this.registrarInventario = this.formBuilder.group({
            producto_inventario: ['', [Validators.required]],
            costo_inventario: ['', [Validators.required]],
            cantidad_inventario: ['', [Validators.required]],
            proveedor_inventario: ['', [Validators.required]],
            vencimiento_inventario: [null, []],
            orden_inventario: ['', []],
            invima_inventario: ['', []],
            lote_inventario: ['', [Validators.required]],
            bodega_inventario: ['', [Validators.required]],
            ubicacion_inventario: ['', [Validators.required]],
            observacion_inventario: ['', []]
    });
  };

If it helps, you let me know, but also ...

    
answered by 10.09.2018 / 00:04
source