@filip.mam
@filip.mam
@filip.mam
@filip.mam
@filip.mam
@filip.mam
@filip.mam
@filip.mam
@filip.mam
@filip.mam
@filip.mam
@filip.mam
const routes = [{
path: "feature-a",
component: FeatureAComponent
},
{
path: "feature-b",
component: FeatureBComponent
},
{
path: "feature-c",
component: FeatureCComponent
}]
@filip.mam
@filip.mam
@filip.mam
@filip.mam
<nav-button routerLink="movies-ranking"></nav-button>
<nav-button routerLink="tv-shows-rankig"></nav-button>
<nav-button routerLink="movie-finder"></nav-button>
<nav-button routerLink="profile"></nav-button>
...
<router-outlet></router-outlet>
...
routes = [{
path: "movies-ranking",
component: MoviesRankingComponent
},
{
path: "tv-shows-ranking",
component: TvShowsRankingComponent
},
...]
@filip.mam
moviesList: Movie[] = [...]
...
<div *ngFor="let movie of movieList">
...
</div>
@filip.mam
moviesList: Movie[] = []
...
<div *ngFor="let movie of []">
...
</div>
@filip.mam
@Component({
...
})
class MoviesRankingComponent {
movieList: Movie[] = [];
constructor(http: Http) {
http.get('api/movies').subscribe(
movies => this.movieList = movies;
);
}
}
@filip.mam
@filip.mam
@filip.mam
@filip.mam
@filip.mam
const routes = [{
path: "movies-ranking",
component: MoviesListComponent
}]
@filip.mam
const routes = [{
path: "movies-ranking",
component: MoviesRankingComponent,
resolve: {
movies: MoviesResolver
}
}]
@filip.mam
@Component({
...
})
class MoviesRankingComponent {
movieList: Movie[] = [];
constructor(http: Http) {
http.get('api/movies').subscribe(
movies => this.movieList = movies;
);
}
}
@filip.mam
@Injectable()
class MoviesResolver implements Resolve<Movie[]> {
constructor(http: Http) {}
public resolve(): Observable<Movie[]> {
return this.http.get("api/movies");
}
}
@filip.mam
@Component({
...
})
class MoviesRankingComponent {
movieList: Movie[] = this.activatedRoute.snapshot.data.movies;
constructor(private activatedRoute: ActivatedRoute) {}
}
@filip.mam
@Component({
...
})
class MoviesRankingComponent {
movieList: Movie[] = this.activatedRoute.snapshot.data.movies;
constructor(private activatedRoute: ActivatedRoute) {}
}
...
const routes = [{
path: "movies-ranking",
component: MoviesRankingComponent,
resolve: {
movies: MoviesResolver
}
}]
@filip.mam
@filip.mam
@filip.mam
public resolve(): Observable<Movie[]> {
return this.http.get("api/tv-shows");
}
...
const tvShowsRankingRoutes = [{
path: "",
component: moviesRankingComponent,
resolver: {
tvShows: TvShowsResolver
}
}]
...
constructor(route: ActivatedRoute) {
this.tvShows = route.snapshot.data.tvShows
}
@filip.mam
const routes = [{
path: "movies-ranking",
component: MoviesRankingComponent,
resolve: {
movies: MoviesResolver
}
},
{
path: "tv-shows-ranking",
component: TvShowsRankingComponent,
resolve: {
movies: TvShowsResolver
}
}]
@filip.mam
const routes = [{
path: "movies-finder",
component: MoviesFinderComponent,
resolve: {
movieFinderData: MovieFinderResolver
}
}]
@filip.mam
const routes = [{
path: "movies-finder",
component: MoviesFinderComponent,
resolve: {
movies: MoviesResolver,
tvShows: TvShowsResolver
}
}]
@filip.mam
const routes = [{
path: "movies-finder",
component: MoviesFinderComponent,
resolve: {
movies: MoviesResolver,
tvShows: TvShowsResolver
}
}]
...
constructor(route: ActivatedRoute) {
this.movies = route.snapshot.data.movies;
this.tvShows = route.snapshot.data.tvShows;
}
@filip.mam
@filip.mam
@filip.mam
@Injectable()
export class NotificationService() {
...
public showLoading(): void {
...
}
public hideLoading(): void {
...
}
}
@filip.mam
@Injectable()
class MoviesResolver {
constructor(http: Http, notifitactionService: NotifitactionService) {}
public resolve(): Observable<Movie[]>
notifitactionService.showNotification();
http.get('api/movies').subscribe(movies => {
notifitactionService.hideNotification();
return movies;
);
}
}
@filip.mam
@filip.mam
@Component({
...
})
class MainComponent {
constructor(router: Router, notificationService: NotificationService) {
this.router.events.subscribe(event) {
if (event instanceof ResolveStart) {
this.showLoading();
}
if (event (instanceof ResolveEnd) {
this.hideLoading();
}
}
}
@filip.mam
@filip.mam
@filip.mam
@filip.mam
@Injectable()
export class NotificationService() {
...
public showLoading(): void {
...
}
public hideLoading(): void {
...
}
public showError(): void {
...
}
}
@filip.mam
@Injectable()
class MoviesResolver implement Resolve<Movie[]> {
constructor(http: Http) {}
public resolve(): Observable<Movie[]> {
return this.http.get("api/movies");
}
}
@filip.mam
@Injectable()
class MoviesResolver implement Resolve<Movie[]> {
constructor(http: Http, notificationService: NotificationService) {}
public resolve(): Observable<Movie[]> {
return this.http.get("api/movies")
.catch(error => {
this.handleError(error);
notificationService.showErorr();
});
}
private handleError(error): void {...}
}
@filip.mam
@NgModule({
imports: [RouterModule.forRoot(routes, {
errorHandler: AppErrorHandler
})]
})
@filip.mam
class errorHandler() implements ErrorHandler {
constructor(private notificationService: NotificationService) {}
public handleError(error) {
...
this.notificationService.showError();
}
}
@filip.mam
@filip.mam