PatrickJS/NG6-starter

I must use $apply() to see changes...?

edin-m opened this issue · 1 comments

I have simple component/controller/html for "file manager" so:

html:

  <div>
    {{ ($ctrl.wickedSick || {}) | json }}
  </div>

component:

export default {
  restrict: 'E',
  bindings: {},
  template,
  controller
};

and controller:

class FileManagerController {
  constructor($scope) {
    this.wickedSick = 'wicked sick !!! 123';
    setTimeout(() => {
      this.wickedSick = 'new value';
      $scope.$apply();
    }, 5000);
  }
}

If I don't have $scope.$apply() I don't se resulting changes. And I would like not to use $apply() manually... Am I doing something wrong?

fesor commented

you should wrap all async functions to make them start digest cycle. In case of setTimeout angular provides you $timeout service which handles digest for you.