<app-top-bar></app-top-bar>
<div class="container">
- <h3>Hallo Welt!</h3>
+ <router-outlet></router-outlet>
</div>
import { AppComponent } from './app.component';
import { TopBarComponent } from './top-bar/top-bar.component';
+import { ProductListComponent } from './product-list/product-list.component';
@NgModule({
declarations: [
AppComponent,
- TopBarComponent
+ TopBarComponent,
+ ProductListComponent
],
imports: [
BrowserModule,
RouterModule.forRoot([
+ { path: '', component: ProductListComponent }
])
],
providers: [],
--- /dev/null
+<h2>Products</h2>
+
+<div *ngFor="let product of products, index as productId">
+
+ <h3>
+ <a [title]="product.name + ' details'" [routerLink]="['/products',productId]"> {{ product.name }} </a>
+ </h3>
+ <p *ngIf="product.description"> <em>Description: </em> {{ product.description }} </p>
+ <p> <strong>{{ product.price }} €</strong> </p>
+
+ <button (click)="share()">
+ Share
+ </button>
+</div>
--- /dev/null
+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();
+ });
+});
--- /dev/null
+import { Component } from '@angular/core';
+
+import { products } from '../products';
+
+@Component({
+ templateUrl: './product-list.component.html',
+ styleUrls: ['./product-list.component.css']
+})
+export class ProductListComponent {
+ products = products;
+
+ share() {
+ window.alert('The product has been pimmelled!');
+ }
+}
--- /dev/null
+export const products = [
+ {
+ name: 'Phone XXL',
+ price: 799,
+ description: 'A large phone with one of the best screens'
+ },
+ {
+ name: 'Phone Minion',
+ price: 699,
+ description: 'A great phone with one of the best cameras'
+ },
+ {
+ name: 'Pimmel-Phone',
+ price: 299,
+ description: ''
+ }
+];