L
L
Leopandro2018-06-04 22:16:00
Angular
Leopandro, 2018-06-04 22:16:00

Why don't callback functions trigger ngClass firings in angular 5?

Here is the function to plot the route in google maps:

calculateAndDisplayRoute(callback = null) {
    var waypts = [];
    this.directionsService.route({
      origin: "Аэропорт, Республика Башкортостан, Россия",
      destination: $('#address_to').val(),
      waypoints: waypts,
      optimizeWaypoints: true,
      travelMode: 'DRIVING'
    }, (response, status) => {
        if (status === 'OK') {
          this.setLengthByResponse(response);
          this.marker.setMap(null);
          this.directionsDisplay.setDirections(response);
          callback ? callback(true) : null;
        } else {
          callback ? callback(false) : null;
        }
    });

This function calls it:
this.calculateAndDisplayRoute((result) => {
        console.log(result);
        if (result) {
          $("#terminal-steps").steps("next");
        }
        else {
          this.errors['address'] = ['Уточните адрес или выберите адрес из списка'];
        }
      });

As you can see, if it was not possible to route to the address, an error message is added.
Next , ngClass is assigned this function:
hasError(field)
  {
    let classList = {
      'has-error' : this.errors[field] != undefined
    };
    return classList;
  }

Weirdness occurs - the message is not displayed and ngClass does not fire, until I click on another button or click on input. It means that something stops the operation of this ngClass, without callbacks everything worked fine. What could it be?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shvets, 2018-06-04
@Leopandro

https://habr.com/post/327004/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question