Last active
August 28, 2020 20:34
-
-
Save elpddev/6ea18b10f822e24ff07c1fdfad4c7f21 to your computer and use it in GitHub Desktop.
Movies Service #angularjs #medium #article-hierarchical-di-ng
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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