More defensive programming in angularjs services.

In most cases check that a variable is not null before trying to operate on it or pass it as argument to a function call.

Also removed some unused services from the angularjs dependency injection in several files.