V
V
Vladimir2016-12-23 15:18:18
Angular
Vladimir, 2016-12-23 15:18:18

$animate.addClass( does not always add a class if fired on the onmouseover event?

A method sits on the onmouseover event on one of the component elements, which launches $animate.addClass(
None of the variables that are in this of the controller itself change, the controller is connected as ControllerAs, while the class does not change on the element itself and the promise does not work.

let el = angular.element(elements[this.activeIndex]);
        let elm = elements[this.activeIndex];

        //el.addClass('active'); // это работает

        let promise = $animate.addClass(elm, 'active');
        console.log('element active 1', el.hasClass('active'));// показывает false
        promise.then(()=>{
          console.log('set element active 2', el.hasClass('active'));//это не отрабатывает
        });

Confused in the documentation is this phrase
Upon execution, the addClass operation will only be handled after the next digest

https://docs.angularjs.org/api/ng/service/$animate

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question