A better way of sharing data across views is to build a custom service. A service is essentially a little class that we can access once it's injected into our controllers—just as we have seen with $scope.
There are three kinds of services within AngularJS: .service(), .factory(), and .value(). All of them act as singletons—design patterns that restrict it to only be instantiated to one object. We'll touch upon all of them before we build our own.