✨ Created draft for ArtistComponent.
This commit is contained in:
parent
e4a04a675f
commit
4fa4ba708e
@ -7,9 +7,9 @@ import { AlbumsComponent } from './components/albums/albums.component';
|
|||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{ path: '', component: HomeComponent },
|
{ path: '', component: HomeComponent },
|
||||||
{ path: 'artists/:id', component: ArtistsComponent },
|
{ path: 'artists/:id', component: ArtistsComponent },
|
||||||
{ path: 'artists/', component: ArtistsComponent },
|
{ path: 'artists', component: ArtistsComponent },
|
||||||
{ path: 'albums/:id', component: AlbumsComponent },
|
{ path: 'albums/:id', component: AlbumsComponent },
|
||||||
{ path: 'albums/', component: AlbumsComponent }
|
{ path: 'albums', component: AlbumsComponent }
|
||||||
];
|
];
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
|
@ -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>
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { DataService } from 'src/app/services/data.service';
|
||||||
|
import { ActivatedRoute } from '@angular/router';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-artists',
|
selector: 'app-artists',
|
||||||
@ -7,9 +9,33 @@ import { Component, OnInit } from '@angular/core';
|
|||||||
})
|
})
|
||||||
export class ArtistsComponent implements OnInit {
|
export class ArtistsComponent implements OnInit {
|
||||||
|
|
||||||
constructor() { }
|
artistData;
|
||||||
|
artists;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private data: DataService,
|
||||||
|
private route: ActivatedRoute
|
||||||
|
) { }
|
||||||
|
|
||||||
ngOnInit() {
|
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();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user