From ab2a25d324e38b00007e59075be0fb6b6074b292 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Fri, 22 Jun 2018 17:37:22 +0200 Subject: [PATCH] number field --- src/app/app.component.html | 12 +++++++++ src/app/app.module.ts | 4 ++- .../number-field.component.spec.ts | 25 +++++++++++++++++++ .../number-field/number-field.component.ts | 23 +++++++++++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 src/app/number-field/number-field.component.spec.ts create mode 100644 src/app/number-field/number-field.component.ts diff --git a/src/app/app.component.html b/src/app/app.component.html index ed6639e..607b352 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -13,4 +13,16 @@ + + + + + + + + + + + + diff --git a/src/app/app.module.ts b/src/app/app.module.ts index a4cab8b..97cc3bf 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -6,6 +6,7 @@ import { AppComponent } from './app.component'; import { LedindicatorComponent } from './ledindicator/ledindicator.component'; import { OnOffButtonComponent } from './on-off-button/on-off-button.component'; import { LedButtonGroupComponent } from './led-button-group/led-button-group.component'; +import { NumberFieldComponent } from './number-field/number-field.component'; @NgModule({ @@ -13,7 +14,8 @@ import { LedButtonGroupComponent } from './led-button-group/led-button-group.com AppComponent, LedindicatorComponent, OnOffButtonComponent, - LedButtonGroupComponent + LedButtonGroupComponent, + NumberFieldComponent ], imports: [ BrowserModule diff --git a/src/app/number-field/number-field.component.spec.ts b/src/app/number-field/number-field.component.spec.ts new file mode 100644 index 0000000..75b95ef --- /dev/null +++ b/src/app/number-field/number-field.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { NumberFieldComponent } from './number-field.component'; + +describe('NumberFieldComponent', () => { + let component: NumberFieldComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ NumberFieldComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(NumberFieldComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/number-field/number-field.component.ts b/src/app/number-field/number-field.component.ts new file mode 100644 index 0000000..4e6f6c5 --- /dev/null +++ b/src/app/number-field/number-field.component.ts @@ -0,0 +1,23 @@ +import { Component, Input, OnInit } from '@angular/core'; +import { MqttclientService } from '../mqttclient.service' + +@Component({ + selector: 'app-number-field', + template: ` + {{value}} + ` +}) +export class NumberFieldComponent implements OnInit { + + @Input() topic : string + value: number + + constructor(private mqttclientService : MqttclientService) { } + + ngOnInit() { + this.mqttclientService.register(this.topic, (message: string) => { + this.value = parseInt(message) + }) + } + +}