Controller communication in AngularJS

Quite often there is a need to pass data from one controller to another. This is relatively easy if we need to pass data from child to parent controller, but not so straight forward when controllers are not in that relationship.
Still, there’s quite a few ways of achieving that, differing in ease of implementation (though none are hard), performance and ease of maintenance.

Angular offers emit/broadcast/on methods on a scope, which are a lot like events in say C#, but they only broadcasted up and down in scope inheritance, so if you need to share data with sibling or some random controller in your app you need to jump through the hoops. Continue reading “Controller communication in AngularJS”

Data mocking in angular E2E testing

We needed to create a suite of e2e tests for our web app, preferably without having to hit the database for obvious reasons.
So basically I wanted to have a solution that satisfies these requirements:

  • Allows easy switch between real and test data, for example by specifying a URL parameter.
  • Allow specifying a mock data source, and a way to manipulate that mock data after it was loaded from the source.

Angular has a fake $httpBackend implementation designed specifically for providing a mock data response when you’re using $http service. Continue reading “Data mocking in angular E2E testing”