4: Add Services
authorKai Moritz <kai@juplo.de>
Sat, 2 May 2020 19:33:23 +0000 (21:33 +0200)
committerKai Moritz <kai@juplo.de>
Sat, 2 May 2020 19:35:40 +0000 (21:35 +0200)
d) Show messages - Create the MessageService

src/app/message.service.spec.ts [new file with mode: 0644]
src/app/message.service.ts [new file with mode: 0644]

diff --git a/src/app/message.service.spec.ts b/src/app/message.service.spec.ts
new file mode 100644 (file)
index 0000000..24d2d1d
--- /dev/null
@@ -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 (file)
index 0000000..439212d
--- /dev/null
@@ -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 = [];
+  }
+}