10 changed files with 110 additions and 29 deletions
Binary file not shown.
@ -0,0 +1,24 @@ |
|||||
|
<h1>Calendar</h1> |
||||
|
|
||||
|
<p>This component demonstrates fetching data from the server.</p> |
||||
|
|
||||
|
<p *ngIf="!forecasts"><em>Loading...</em></p> |
||||
|
|
||||
|
<table class='table table-striped' *ngIf="forecasts"> |
||||
|
<thead> |
||||
|
<tr> |
||||
|
<th>Date</th> |
||||
|
<th>Temp. (C)</th> |
||||
|
<th>Temp. (F)</th> |
||||
|
<th>Summary</th> |
||||
|
</tr> |
||||
|
</thead> |
||||
|
<tbody> |
||||
|
<tr *ngFor="let forecast of forecasts"> |
||||
|
<td>{{ forecast.dateFormatted }}</td> |
||||
|
<td>{{ forecast.temperatureC }}</td> |
||||
|
<td>{{ forecast.temperatureF }}</td> |
||||
|
<td>{{ forecast.summary }}</td> |
||||
|
</tr> |
||||
|
</tbody> |
||||
|
</table> |
@ -0,0 +1,40 @@ |
|||||
|
import { Component, Inject } from '@angular/core'; |
||||
|
import { HttpClient } from '@angular/common/http'; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'app-calendar', |
||||
|
templateUrl: './calendar.component.html' |
||||
|
}) |
||||
|
export class CalendarComponent { |
||||
|
public forecasts: CalendarForecast[]; |
||||
|
|
||||
|
constructor(http: HttpClient, @Inject('BASE_URL') baseUrl: string) { |
||||
|
console.log("ws connecting to ws" + baseUrl.substring(4, baseUrl.length) + "ws/calendar"); |
||||
|
var ws = new WebSocket("ws" + baseUrl.substring(4, baseUrl.length) + "ws/calendar"); |
||||
|
|
||||
|
ws.onopen = function () { |
||||
|
|
||||
|
// Web Socket is connected, send data using send()
|
||||
|
ws.send("Message to send"); |
||||
|
alert("Message is sent..."); |
||||
|
}; |
||||
|
|
||||
|
ws.onmessage = function (evt) { |
||||
|
var received_msg = evt.data; |
||||
|
alert("Message is received..."); |
||||
|
}; |
||||
|
|
||||
|
ws.onclose = function () { |
||||
|
|
||||
|
// websocket is closed.
|
||||
|
alert("Connection is closed..."); |
||||
|
}; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
interface CalendarForecast { |
||||
|
dateFormatted: string; |
||||
|
temperatureC: number; |
||||
|
temperatureF: number; |
||||
|
summary: string; |
||||
|
} |
Loading…
Reference in new issue