From: Kai Moritz Date: Fri, 20 Dec 2019 15:23:00 +0000 (+0100) Subject: Product-Details aus Tutorial übernommen X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=bfe15f71205934d62304ce869cb81aeaec551593;p=examples%2Fangular-tutorial Product-Details aus Tutorial übernommen --- diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 4cd6aea..a20e2d0 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -5,17 +5,20 @@ import { RouterModule } from '@angular/router'; import { AppComponent } from './app.component'; import { TopBarComponent } from './top-bar/top-bar.component'; import { ProductListComponent } from './product-list/product-list.component'; +import { ProductDetailsComponent } from './product-details/product-details.component'; @NgModule({ declarations: [ AppComponent, TopBarComponent, - ProductListComponent + ProductListComponent, + ProductDetailsComponent ], imports: [ BrowserModule, RouterModule.forRoot([ - { path: '', component: ProductListComponent } + { path: '', component: ProductListComponent }, + { path: 'products/:productId', component: ProductDetailsComponent } ]) ], providers: [], diff --git a/src/app/product-details/product-details.component.css b/src/app/product-details/product-details.component.css new file mode 100644 index 0000000..e69de29 diff --git a/src/app/product-details/product-details.component.html b/src/app/product-details/product-details.component.html new file mode 100644 index 0000000..a86d6b8 --- /dev/null +++ b/src/app/product-details/product-details.component.html @@ -0,0 +1,7 @@ +

Product Details

+ +
+

{{ product.name }}

+

{{ product.price | currency }}

+

{{ product.description }}

+
diff --git a/src/app/product-details/product-details.component.spec.ts b/src/app/product-details/product-details.component.spec.ts new file mode 100644 index 0000000..8de32d0 --- /dev/null +++ b/src/app/product-details/product-details.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ProductDetailsComponent } from './product-details.component'; + +describe('ProductDetailsComponent', () => { + let component: ProductDetailsComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ProductDetailsComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ProductDetailsComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/product-details/product-details.component.ts b/src/app/product-details/product-details.component.ts new file mode 100644 index 0000000..049b7cc --- /dev/null +++ b/src/app/product-details/product-details.component.ts @@ -0,0 +1,21 @@ +import { Component, OnInit } from '@angular/core'; +import { ActivatedRoute } from '@angular/router'; +import { products } from '../products'; + +@Component({ + selector: 'app-product-details', + templateUrl: './product-details.component.html', + styleUrls: ['./product-details.component.css'] +}) +export class ProductDetailsComponent implements OnInit { + product; + + constructor(private route: ActivatedRoute) { } + + ngOnInit() { + this.route.paramMap.subscribe(params => { + this.product = products[+params.get('productId')]; + }); + } + +}