Skip to content

Instantly share code, notes, and snippets.

@elpddev
Last active August 28, 2020 20:34
Show Gist options
  • Save elpddev/6ea18b10f822e24ff07c1fdfad4c7f21 to your computer and use it in GitHub Desktop.
Save elpddev/6ea18b10f822e24ff07c1fdfad4c7f21 to your computer and use it in GitHub Desktop.
Movies Service #angularjs #medium #article-hierarchical-di-ng
class MoviesService {
static $inject = ['$http', 'auth'];
movies = Promise.resolve([]);
constructor(
private $http: IHttpService,
private auth: AuthService,
) {}
getMovies() {
if (_.isNil(this.movies)) {
this.movies = this.auth.getToken()
.then((token) => {
return $http.get('my-site.example.com/movies', {
headers: {
Authorization: token,
},
});
});
}
return this.movies;
}
}
moviesApp.service('movies', MoviesService);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment