Battalgazi
Battalgazi

Reputation: 379

Acess the value of a key in the html component

i'll keep it simple.I have the following map:

export class Component {

    total: Map<string, number> = new Map([["test1", 2],["test2",3]])
}

How can I access a particular value using its key in the html component?.I tried the following code without success and all examples that i found use an ngFor which i don't want to use.

test.component.html

{{total[test1]}}
{{total.get(test1)}}

Thanks in advance.

Upvotes: 1

Views: 40

Answers (2)

Venomy
Venomy

Reputation: 2244

Don't forget the quotes for the string type key.

{{total.get('test1')}}

Upvotes: 1

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657238

It's an array of arrays, therefore an additionl index access is required

{{total[0]['test1']}}
{{total[1]['test2']}}

or

{{total[0].test1}}
{{total[1].test2}}

Upvotes: 1

Related Questions