Skip to content

Commit

Permalink
feat: got demo app to test breadcrumbs
Browse files Browse the repository at this point in the history
  • Loading branch information
udayvunnam committed Jul 19, 2020
1 parent 5d491d7 commit 5dc1acb
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 30 deletions.
4 changes: 3 additions & 1 deletion apps/got-demo/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { ROUTER_COMPONENTS, AppRoutingModule } from './app.routing.module';
import { HttpClientModule } from '@angular/common/http';

@NgModule({
declarations: [AppComponent, ...ROUTER_COMPONENTS],
imports: [
BrowserModule,
AppRoutingModule
AppRoutingModule,
HttpClientModule
],
providers: [],
bootstrap: [AppComponent],
Expand Down
6 changes: 1 addition & 5 deletions apps/got-demo/src/app/app.routing.module.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { RouterModule, Routes } from "@angular/router";
import { NgModule } from "@angular/core";
import { HousesComponent } from './houses/houses.component';
import { CharactersComponent } from './characters/characters.component';
import { BooksComponent } from './books/books.component';

export const appRoutes: Routes = [
{
path: "books",
component: BooksComponent,
}, {
path: "characters",
component: CharactersComponent,
}, {
path: "houses",
component: HousesComponent,
Expand All @@ -23,4 +19,4 @@ export const appRoutes: Routes = [
})
export class AppRoutingModule { }

export const ROUTER_COMPONENTS = [BooksComponent, CharactersComponent, HousesComponent];
export const ROUTER_COMPONENTS = [BooksComponent, HousesComponent];
9 changes: 8 additions & 1 deletion apps/got-demo/src/app/books/books.component.html
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
<p>books works!</p>
<div *ngIf="books$ | async as books; else loading">
<ul>
<li *ngFor="let book of books">
<a [routerLink]="['/books', book.url[book.url.length-1] ]" [queryParams]="{ pages: book.numberOfPages }">{{book.name}}</a>
</li>
</ul>
</div>
<ng-template #loading>loading ...</ng-template>
8 changes: 5 additions & 3 deletions apps/got-demo/src/app/books/books.component.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { Component, OnInit } from '@angular/core';
import { DataService } from '../data.service';
import { Observable } from 'rxjs';

@Component({
selector: 'got-books',
templateUrl: './books.component.html',
styleUrls: ['./books.component.css']
})
export class BooksComponent implements OnInit {

constructor() { }
books$: Observable<any[]>
constructor(private dataService: DataService) { }

ngOnInit(): void {
this.books$ = this.dataService.getBooks();
}

}
Empty file.
1 change: 0 additions & 1 deletion apps/got-demo/src/app/characters/characters.component.html

This file was deleted.

15 changes: 0 additions & 15 deletions apps/got-demo/src/app/characters/characters.component.ts

This file was deleted.

27 changes: 27 additions & 0 deletions apps/got-demo/src/app/data.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';

const options = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) };


@Injectable({
providedIn: 'root'
})
export class DataService {
private API = `https://www.anapioficeandfire.com/api`;

constructor(private http: HttpClient) { }

getBooks(): Observable<any[]> {
return this.http.get<any[]>(`${this.API}/books`);
}

getCharacters(): Observable<any[]> {
return this.http.get<any[]>(`${this.API}/characters`);
}

getHouses(): Observable<any[]> {
return this.http.get<any[]>(`${this.API}/houses`);
}
}
9 changes: 8 additions & 1 deletion apps/got-demo/src/app/houses/houses.component.html
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
<p>houses works!</p>
<div *ngIf="houses$ | async as houses; else loading">
<ul>
<li *ngFor="let book of houses">
{{book.name}}
</li>
</ul>
</div>
<ng-template #loading>loading ...</ng-template>
8 changes: 5 additions & 3 deletions apps/got-demo/src/app/houses/houses.component.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { DataService } from '../data.service';

@Component({
selector: 'got-houses',
templateUrl: './houses.component.html',
styleUrls: ['./houses.component.css']
})
export class HousesComponent implements OnInit {

constructor() { }
houses$: Observable<any[]>
constructor(private dataService: DataService) { }

ngOnInit(): void {
this.houses$ = this.dataService.getHouses();
}

}

0 comments on commit 5dc1acb

Please sign in to comment.