Skip to content

Commit

Permalink
Completed module
Browse files Browse the repository at this point in the history
  • Loading branch information
armstrong99 committed Oct 29, 2019
1 parent 653b704 commit 5065282
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<app-product-page></app-product-page>
<app-product-list></app-product-list>
6 changes: 4 additions & 2 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import { AppComponent } from './app.component';
import { ProductPageComponent } from './product-page/product-page.component';
import { ProductDescriptionComponent } from './product-description/product-description.component';
import {ProductService} from './product.service';
import { ProductTracklistingComponent } from './product-tracklisting/product-tracklisting.component'
import { ProductTracklistingComponent } from './product-tracklisting/product-tracklisting.component';
import { ProductListComponent } from './product-list/product-list.component'
@NgModule({
declarations: [
AppComponent,
ProductPageComponent,
ProductDescriptionComponent,
ProductTracklistingComponent
ProductTracklistingComponent,
ProductListComponent
],
imports: [
BrowserModule,
Expand Down
Empty file.
5 changes: 5 additions & 0 deletions src/app/product-list/product-list.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<ul>
<li *ngFor = "{let product of products}">
{{product.albumName}}
</li>
</ul>
25 changes: 25 additions & 0 deletions src/app/product-list/product-list.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { ProductListComponent } from './product-list.component';

describe('ProductListComponent', () => {
let component: ProductListComponent;
let fixture: ComponentFixture<ProductListComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ProductListComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(ProductListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
17 changes: 17 additions & 0 deletions src/app/product-list/product-list.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Component, OnInit } from '@angular/core';
import { Product } from '../product'
import {ProductService} from '../product.service'
@Component({
selector: 'app-product-list',
templateUrl: './product-list.component.html',
styleUrls: ['./product-list.component.css']
})
export class ProductListComponent implements OnInit {
products: Product[];
constructor(private _productService: ProductService) { }

ngOnInit() {
this._productService.getProducts().subscribe(response => this.products = response)
}

}
8 changes: 6 additions & 2 deletions src/app/product.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@ import {Http, Response } from '@angular/http'
import 'rxjs/add/operator/map'
import { Album } from './album'
import { Observable } from 'rxjs/Observable'

import {Product} from './product'

@Injectable()
export class ProductService {

private _albumUrl = '../assets/album.json';

private _productsUrl = "../assets/products.json";

constructor(private _http: Http) { }

getAlbum(id: number): Observable<Album> {
return this._http.get(this._albumUrl).map((response) => <Album>response.json());
}


getProducts(): Observable<Product[]> {
return this._http.get(this._productsUrl).map(response => <Product[]>response.json())
}
}
5 changes: 5 additions & 0 deletions src/app/product.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface Product {
id: number;
artistName: string;
albumName: string;
}

0 comments on commit 5065282

Please sign in to comment.