Angular guidelines suggest utilizing Angular services and expressions:
It is recommended to use services like $window and $location in functions called from expressions. These services offer a way to access global variables that can be easily mocked.
- https://docs.angularjs.org/guide/expression#context
However, these services may not be readily available in the view scope by default, for example:
{{$location || 'Undefined'}}
This code will output "Undefined".
If I need to use the $location
service within a view, do I have to inject it into the scope?
/* some controller */ function ($scope, $location) {
$scope.$location = $location;
}