Created draft for ArtistComponent.

This commit is contained in:
corner 2019-09-21 16:48:15 +02:00
parent e4a04a675f
commit 4fa4ba708e
3 changed files with 62 additions and 4 deletions

View File

@ -7,9 +7,9 @@ import { AlbumsComponent } from './components/albums/albums.component';
const routes: Routes = [
{ path: '', component: HomeComponent },
{ path: 'artists/:id', component: ArtistsComponent },
{ path: 'artists/', component: ArtistsComponent },
{ path: 'artists', component: ArtistsComponent },
{ path: 'albums/:id', component: AlbumsComponent },
{ path: 'albums/', component: AlbumsComponent }
{ path: 'albums', component: AlbumsComponent }
];
@NgModule({

View File

@ -1 +1,33 @@
<p>artists works!</p>
<ng-container *ngIf="( artists | async ) as artists; else artistInfo">
<ul>
<li *ngFor="let artist of artists.result">
<a [routerLink]="'/artists/' + artist.id">{{ artist.name }}</a>
</li>
</ul>
</ng-container>
<ng-template #artistInfo>
<div *ngIf="( artistData | async ) as data">
<h1>{{ data.result[0].name }}'s profile</h1>
<h4>{{ data.result[0].name }}'s albums</h4>
<ul>
<li *ngFor="let album of data.result[0].albums">
{{ album.name }}
</li>
</ul>
<h4>{{ data.result[0].name }}'s songs</h4>
<ul>
<li *ngFor="let song of data.result[0].songs">
{{ song.name }}
</li>
</ul>
</div>
</ng-template>

View File

@ -1,4 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { DataService } from 'src/app/services/data.service';
import { ActivatedRoute } from '@angular/router';
@Component({
selector: 'app-artists',
@ -7,9 +9,33 @@ import { Component, OnInit } from '@angular/core';
})
export class ArtistsComponent implements OnInit {
constructor() { }
artistData;
artists;
constructor(
private data: DataService,
private route: ActivatedRoute
) { }
ngOnInit() {
this.route.paramMap.subscribe(params => {
// If the id argument is given...
if (params.has('id')) {
// ... then get artist data ...
this.artistData = this.data.getArtist(params.get('id'));
} else {
// Otherwise, get all artists and list them out.
this.artists = this.data.getAllArtists();
}
});
}
}