AngularJS

Topics related to AngularJS:

Getting started with AngularJS

Controllers

Built-in directives

Modules

Components

Custom Directives

Filters

Services

Dependency Injection

Providers cannot be injected into run blocks.

Services or Values cannot be injected into config blocks.

Make sure to annotate your injections so your code will not break on minification.

Unit tests

This topic provides examples for unit testing the various constructs in AngularJS. Unit tests are often written using using Jasmine, a popular behavior driven testing framework. When unit testing angular constructs, you will need to include ngMock as a dependency when running the unit tests.

Profiling and Performance

Events

Sharing Data

A very common question when working with Angular is how to share data between controllers. Using a service is the most frequent response and this is a simple example demonstrating a factory pattern to share any type of data object between two or more controllers. Because it is a shared object reference, an update in one controller will be immediately available in all other controllers using the service. Note that both service and factory and both providers.

How data binding works

So while this Data Binding concept on a whole is easy on the developer, it is quite heavy on the Browser since Angular listens to every event change and runs the Digest Cycle. Because of this, whenever we attach some model to the view, make sure that Scope is as optimized as possible

Routing using ngRoute

ng-class directive

Directives using ngModelController

ui-router

Custom filters

Built-in helper Functions

digest loop walkthrough

Angular $scopes

Angular uses a tree of scopes to bind the logic (from controllers, directives, etc) to the view and are the primary mechanism behind change detection in AngularJS. A more detailed reference for scopes can be found at docs.angularjs.org

The root of the tree is accessible as via inject-able service $rootScope. All child $scopes inherit the methods and properties of their parent $scope, allowing children access to methods without the use of Angular Services.

AngularJS gotchas and traps

Using AngularJS with TypeScript

$http request

Constants

UPPERCASE your constant: Writing constant in capital is a common best practice used in many languages. It's also useful to clearly identify the nature of injected elements:

When you see .controller('MyController', function($scope, Profile, EVENT)), you instantly know that:

  • $scope is an angular element
  • Profile is a custom Service or Factory
  • EVENT is an angular constant

Form Validation

Angular promises with $q service

Prepare for Production - Grunt

Debugging

Providers

Decorators

Decorator is function that allow a service, factory, directive or filter to be modified prior to its usage. Decorator is used to override or modify the behavior of the service. The return value of the decorator function may be the original service, or a new service that replaces, or wraps and delegates to, the original service.


Any decorating must be done in angular application's config phase by injecting $provide and using it's $provide.decorator function.

The decorator function has a $delegate object injected to provide access to the service that matches the selector in the decorator. This $delegate will be the service you are decorating. The return value of the function provided to the decorator will take place of the service, directive, or filter being decorated.


One should consider using decorator only if any other approach is not appropriate or proves to be too tedious. If large application is using same service, and one part is changing service behavior, it's easy to create confusion and/or bugs in the process.

Typical use case would be when you have a 3rd party dependency which you can't upgrade but need it to work little differently or extend it.

Grunt tasks

Angular Project - Directory Structure

AngularJS bindings options (`=`, `@`, `&` etc.)

Use this plunker to play with examples.

Lazy loading

  1. If your lazy loaded dependencies require other lazy loaded dependencies make sure you load them in the right order!
angular.module('lazy', [
 'alreadyLoadedDependency1',
 'alreadyLoadedDependency2',
 ...
 {
  files: [
  'path/to/lazily/loaded/dependency1.js',
  'path/to/lazily/loaded/dependency2.js', //<--- requires lazily loaded dependency1
  'path/to/lazily/loaded/dependency.css'
  ],
  serie: true //Sequential load instead of parallel
 }
]);

HTTP Interceptor

Print

Performance Profiling

Distinguishing Service vs Factory

Use of in-built directives

ng-repeat

AngularJS provides these parameters as special variables that are available in the ng-repeat expression and anywhere inside of the HTML tag on which the ng-repeat lives.

Session storage

Angular MVC

ng-style

ng-view

The Self Or This Variable In A Controller

Controllers with ES6

Custom filters with ES6

Migration to Angular 2+

SignalR with AngularJs

angularjs with data filter, pagination etc