From: Kai Moritz Date: Sat, 2 May 2020 19:33:23 +0000 (+0200) Subject: 4: Add Services X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=3d51b3aadd81cc25544a5253e784dda60aa7f207;p=examples%2Fangular-tour-of-heroes 4: Add Services d) Show messages - Create the MessageService --- diff --git a/src/app/message.service.spec.ts b/src/app/message.service.spec.ts new file mode 100644 index 0000000..24d2d1d --- /dev/null +++ b/src/app/message.service.spec.ts @@ -0,0 +1,12 @@ +import { TestBed } from '@angular/core/testing'; + +import { MessageService } from './message.service'; + +describe('MessageService', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('should be created', () => { + const service: MessageService = TestBed.get(MessageService); + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/message.service.ts b/src/app/message.service.ts new file mode 100644 index 0000000..439212d --- /dev/null +++ b/src/app/message.service.ts @@ -0,0 +1,17 @@ +import { Injectable } from '@angular/core'; + +@Injectable({ + providedIn: 'root' +}) +export class MessageService { + + messages : string[] = []; + + add(message : string): void { + this.messages.push(message); + } + + clear(): void { + this.messages = []; + } +}