!stwKHgRhngEqycqwry:matrix.org

Angular-cli

4317 Members
Angular cli9 Servers

Load older messages


SenderMessageTime
5 Jul 2020
@gitter_korporal:matrix.orgHugh Gleaves (Gitter)If I create a web ap project in VS 2019 and select the angular project template option, I get a simple sample project20:13:09
@gitter_korporal:matrix.orgHugh Gleaves (Gitter) I'm curious how the serialization of data from the back end is being done 20:13:27
@gitter_korporal:matrix.orgHugh Gleaves (Gitter) There's an angular interface: 20:13:43
@gitter_korporal:matrix.orgHugh Gleaves (Gitter) interface WeatherForecast {
date: string;
temperatureC: number;
temperatureF: number;
summary: string;
}
20:14:00
@gitter_korporal:matrix.orgHugh Gleaves (Gitter)that looks like the C# interface but the member spellings differ20:14:29
@gitter_korporal:matrix.orgHugh Gleaves (Gitter)also if I comment out say temperatureC in the angular interface, everything seems to work the same, as if it is either ignoreing the interface or something20:15:13
@gitter_kylecannon:matrix.orgKyle Cannon (Gitter) Typescript is a superset of JavaScript. It doesn't serialize or validate at runtime. There is no marshaling 20:16:10
@gitter_derekkite:matrix.orgDerek (Gitter) @Korporal interfaces are compile time only. Their function is to give shape to the data so that as you build it will catch type errors. 20:17:45
@gitter_korporal:matrix.orgHugh Gleaves (Gitter)OK20:18:23
@gitter_korporal:matrix.orgHugh Gleaves (Gitter) interface WeatherForecast {
date: string;
//temperatureC: number;
temperatureF: number;
summary: string;
}
20:18:36
@gitter_korporal:matrix.orgHugh Gleaves (Gitter)if I comment out a member, it still works, the page still has values shown for the field20:19:16
@gitter_korporal:matrix.orgHugh Gleaves (Gitter)in the debugger the data looks as if the member was not commented out20:19:51
@gitter_korporal:matrix.orgHugh Gleaves (Gitter)

import { Component, Inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';

@Component({
selector: 'app-fetch-data',
templateUrl: './fetch-data.component.html'
})
export class FetchDataComponent {
public forecasts: WeatherForecast[];

constructor(http: HttpClient, @Inject('BASE_URL') baseUrl: string) {
http.get<WeatherForecast[]>(baseUrl + 'weatherforecast').subscribe(result => {
this.forecasts = result;
}, error => console.error(error));
}
}

interface WeatherForecast {
date: string;
//temperatureC: number;
temperatureF: number;
summary: string;
}

20:20:35
@gitter_korporal:matrix.orgHugh Gleaves (Gitter)sorry I cant recall how to [paset cpode20:20:56
@gitter_korporal:matrix.orgHugh Gleaves (Gitter)

import { Component, Inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';

@Component({
selector: 'app-fetch-data',
templateUrl: './fetch-data.component.html'
})
export class FetchDataComponent {
public forecasts: WeatherForecast[];

constructor(http: HttpClient, @Inject('BASE_URL') baseUrl: string) {
http.get<WeatherForecast[]>(baseUrl + 'weatherforecast').subscribe(result => {
this.forecasts = result;
}, error => console.error(error));
}
}

interface WeatherForecast {
date: string;
//temperatureC: number;
temperatureF: number;
summary: string;
}
```

20:21:55
@gitter_korporal:matrix.orgHugh Gleaves (Gitter)
import { Component, Inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';

@Component({
  selector: 'app-fetch-data',
  templateUrl: './fetch-data.component.html'
})
export class FetchDataComponent {
  public forecasts: WeatherForecast[];

  constructor(http: HttpClient, @Inject('BASE_URL') baseUrl: string) {
    http.get<WeatherForecast[]>(baseUrl + 'weatherforecast').subscribe(result => {
      this.forecasts = result;
    }, error => console.error(error));
  }
}

interface WeatherForecast {
  date: string;
  //temperatureC: number;
  temperatureF: number;
  summary: string;
}
20:22:34
@gitter_korporal:matrix.orgHugh Gleaves (Gitter)ok20:22:40
@gitter_korporal:matrix.orgHugh Gleaves (Gitter) so if I examine this.forecasts at runtime in the debugger (Visual Studio) the "forecasts" shows that the member temperatureC is not commented out 20:23:28
@gitter_korporal:matrix.orgHugh Gleaves (Gitter) (edited) ... is not ... => ... is (apparently) not ... 20:24:28
@gitter_korporal:matrix.orgHugh Gleaves (Gitter) I don't even know how to begin searching for an explanation for this. 20:30:50
@gitter_derekkite:matrix.orgDerek (Gitter)

@Korporal the api call returns some data. The typescript interface has nothing to do with that. All it does is define a shape, a definition of the data. So if you are working with the WeatherForecast data, something like this:

...
   let C = forecasts.temperatureC;

There will be two errors in your editor and the build. forcasts is an array, and the property doesn't exist in the definition.
That, along with some language extensions, is the extent of Typescript.

20:39:56
@gitter_korporal:matrix.orgHugh Gleaves (Gitter)OK, still puzzled because the associated HTML looks like this (and works as if the member has not been commented out)20:44:12
@gitter_korporal:matrix.orgHugh Gleaves (Gitter)
<h1 id="tableLabel">Weather forecast</h1>

<p>This component demonstrates fetching data from the server.</p>

<p *ngIf="!forecasts"><em>Loading...</em></p>

<table class='table table-striped' aria-labelledby="tableLabel" *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.date }}</td>
      <td>{{ forecast.temperatureC }}</td>
      <td>{{ forecast.temperatureF }}</td>
      <td>{{ forecast.summary }}</td>
    </tr>
  </tbody>
</table>
20:44:27
@gitter_derekkite:matrix.orgDerek (Gitter) @Korporal likely because the configuration isn't set to strict for templates. forecast.temperatureC exists in the javascript object returned from the api call. 20:47:08
@gitter_korporal:matrix.orgHugh Gleaves (Gitter)OK I see (I think)20:48:12
@gitter_korporal:matrix.orgHugh Gleaves (Gitter)so the lexical order of members is simply taken from the source data?20:48:33
@gitter_derekkite:matrix.orgDerek (Gitter)coming from a typed language world, it is definitely odd. Start from the other end. Javascript is untyped. type errors will show up in execution. Typescript is designed to apply typing to an untype javascript. 20:48:46
@gitter_korporal:matrix.orgHugh Gleaves (Gitter)OK thanks20:49:13
@gitter_korporal:matrix.orgHugh Gleaves (Gitter)The back end class looks like this20:49:24
@gitter_derekkite:matrix.orgDerek (Gitter) @Korporal for an api call, yes. hopefully you can get a definition of the data. 20:49:33

There are no newer messages yet.


Back to Room ListRoom Version: 5