I want to know, how can I recreate this C# code in TypeScript
Dictionary<string, List<string>> sas = new Dictionary<string, List<string>>();
sas.Add("11", new List<string> { "a", "b", "c" });
sas.Add("22", new List<string> { "a2", "b2", "c2" });
foreach(var e in sas)
{
Console.WriteLine(e.Key);
foreach(var s in e.Value)
{
Console.WriteLine(s);
}
Console.WriteLine();
}
I expect that I will get in console this:
11
a
b
c
22
a2
b2
c2
Update
And the most important, how can I use code like this in Angular and why I get undefined un my ngOnInit method?
My Answer class
import { Question } from './question';
export class Answer {
AnswerId: number;
Content: string;
IsCorrect: boolean;
Mark: number;
QuestionId: number;
Question: Question;
}
Component code
testInfo: Record<string, Answer[]>;
ngOnInit() {
if (this.id)
this.dataService.getTestStart(this.id)
.subscribe((data: Record<string, Answer[]>) =>
{
this.testInfo = data; this.loaded = true;
console.log(this.testInfo);
for (const key in this.testInfo) {
console.log(key);
for (const s of this.testInfo[key]) {
console.log(s.Content)//here is undefined
}
console.log()
}
});
}
When I try to output s.Content i get undefined. And when I try to output this on page using Angular I got nothing.
<tr *ngFor="let key of testInfo">
<td class="row-number-column">{{key}}</td>
<template *ngFor="let s of testInfo[key]">
<td>
{{s?.content}}
</td>
</template>
</tr>