# AngularJS - controllers

# communication between controllers

ways to communicate between controllers (services + events)

# controllerAs syntax

digging-into-angulars-controller-as-syntax

Le principe c'est de ne plus injecter le scope pour travailler dessus mais d'utiliser le controller pour l'interpolation.

En terme d'achi, le controller n'est plus vraiment un controlleur mais prend sa place dans le MVVM en tant que V (associé au HTML)

le why

# $scope

# $scope must read

# $digest already in progress issue

# EvalAsync() or setTimeOut()

  • scope-evalasync-vs-timeout-in-angularjs
  • EvalSync is to put your thing in the angular loop
  • TimeOut is to delay your thing outside and probably after the angular loop
  • angularjs-evalasync-vs-timeout
  • if code is queued using $evalAsync from a directive, it should run after the DOM has been manipulated by Angular, but before the browser renders
  • if code is queued using $evalAsync from a controller, it should run before the DOM has been manipulated by Angular (and before the browser renders) -- rarely do you want this
  • if code is queued using $timeout, it should run after the DOM has been manipulated by Angular, and after the browser renders (which may cause flicker in some cases)

# $scope dirty checking

# publishing data in the views