import { Component, OnInit } from '@angular/core'; import { NameListService } from '../name-list/name-list.service'; import { BasePage } from '../shared/baseshared/components/base.component'; import { ConfigService } from '../shared/configuration/config.service'; import { BroadcastService } from '../shared/broadcast/broadcast.service'; import { LoggerService } from '../shared/logger/log.service'; /** * This class represents the lazy loaded HomeComponent. */ @Component({ selector: 'my-home', templateUrl: 'home.component.html', styleUrls: ['home.component.css'], }) export class HomeComponent extends BasePage { newName: string; errorMessage: string; names: any[] = []; constructor( configService: ConfigService, broadcastService: BroadcastService, loggerService: LoggerService, public nameListService: NameListService ) { super(configService, broadcastService, loggerService); } public initialize(): void { this.getNames(); } /** * Handle the nameListService observable */ getNames() { this.nameListService.get() .subscribe( names => this.names = names, error => this.errorMessage = error ); } /** * Pushes a new name onto the names array * @return {boolean} false to prevent default form submit behavior to refresh the page. */ addName(): boolean { // TODO: implement nameListService.post this.names.push(this.newName); this.newName = ''; return false; } }