Checklist you can use when you need to perform a code review of an AngularJS 1.x application.
Based on best-practices and recommendations by
controllerAs
bindToController
$
$
prefix is reserved for AngularJS internalsfunction($rootScope, $timeout, MyDependency)
scope
instead of $scope
in link functionng
prefix as it is reserved for AngularJSng-src
instead of src
, ng-href
instead of href
, ng-style
instead of style
, etc. when dynamic values are passed$
services provided by AngularJS whenever possible$timeout
, $interval
, $http
, …$digest
cycleng-cloak
to initially hide elements that are only visible under certain conditions$log
service$log.debug()
to write debug messages to the console$scope.$parent
require
to let directives communicate$urlRouterProvider.otherwise()
to specify the default route in case no route definition matches the request$routerProvider.otherwise()
to specify the default route in case no route definition matches the request$routeChangeError
event listener to handle routing errors$stateChangeError
event listener to handle routing errors$exceptionHandler
service to handle uncaught exceptionsresolve
property of a route or state to load content that is immediately required in the view$sce
service to explicitly tell AngularJS which content can be marked as safe for a context$stateChangeStart
event handler to control access$compile, $parse
and $interpolate
$eval
, $apply
and not in the orderBy
pipengAria
module as a dependency<script>
elements should be as low as possible in document<head>
$digest
loop so if they are slow, they will slow down your application$digest
cycle$digest
cycle$digest
cycles{{ :: expression }}
for content that does not change after initialization$watch
as simple as possibledata.property
instead of deep watching data$digest
cycles so keeping them fast results in better performance$watchCollection
used instead of deep watch where possible?$watchCollection
instead of a deep watch for collections$watchCollection
performs a shallow equality check of the result of the watched expression and its previous value, resulting in better performance$scope.$applyAsync()
$httpProvider
to use $applyAsync
: $httpProvider.useApplyAsync(true);
$digest
cycles when expressions are evaluated around the same timefalse
as third parameter to $timeout
when no watched variables are impacted by its callback$digest
cycles$scope.$on(‘$destroy’, fn)
to clean up resources such as timers and intervalsngModelOptions
to manually control when $digest
cycle should run$digest
cycles