AngularJS Lightning Q&A







Agenda



$observe vs. $watch

Learn 1.3 when 2.0 is coming out?

Large application structures

Configuration phase

Performance Boosts

$observe vs. $watch


$observe is method of Attributes object

$watch is method of Scope object

$observe only in directives, "watches" changes of DOM attribute where interpolation is used "{{}}

$watch watches an expression, could be function or string, if string it is $parsed or evaluated otherwise

both are checked on each $digest cycle

when using $observe, to convert the string back to object use $eval method of the Scope object

Learn 1.3 when 2.0 is coming out?


short answer "yes"
long answer: syntax will change but concepts will remain as well as fundamentals, like binding, dependency injection, services
any time spend now will help with understanding and learning the future version of Angular, also it will be a long time before able to use 2.0

Large application structures



LIFT principle - locating our code is easy, identify code at a glance, flat structure as long as we can, try to stay DRY
folders-by-feature or folders-by-type structures
to help with multi-development environments use repository like TFS, GIT, etc.

Configuration phase


keep module configuration in a separate file
config function using providers to specify the generation of services, for example the $routeProvider specify the creation of $route
executed during the provider registrations and configuration phase
only providers and constants can be injected into configuration blocks, one exception
$provide.decorator useful to intercept creation of services, example $exceptionHandler

Performance Boosts



use debugInfoEnabled method of $compileProvider to remove all additional information of DOM elements regarding binding and scope
use ng-strict-di to prevent dynamic discovery of dependencies, all dependencies combine prove to be explicitly annotated
use useApplyAsync method of $httpProvider to combine processing of several http responses, when they are received in about the same time, about ~10ms window

AngularJS Lightning Q&A 2015-01-21

By Kris Ivanov

AngularJS Lightning Q&A 2015-01-21

  • 1,018