javascriptangularjsangularjs-controllerangularjs-componentsangularjs-digest

AngularJS component: $doCheck won't run for fake HTTP request with $q.when()


I created Simple Angular textarea component with characters counter, made with $doCheck component hook on Plunker, which counts characters on $doCheck hook. I read that it should run for every digest cycle, so it should work:

$ctrl.load = function () {
    HTTPService
      .get()
      .then(_bindElement);
  }
function _bindElement (element) {
    $ctrl.element = element;
  }

Cause at least digets runs - value changes inside component, it is also displayed on parent's <p>. But counter does not change, am I missing something, this is not true that $doCheck runs on every digest cycle? I use $q.when() for simulation of HTTP request - I also tried $timeout to force digest, but it didn't work. Thank you in advance for every help.


Solution

  • I found a solution, I have to manually call digest with timeout when character count changes, cause it looks like assignments inside $doCheck to not trigger digest, and that's why view was out of sync with model. Working plunk: https://plnkr.co/edit/M6I5sB?p=info.