Reputation: 379
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
Reputation: 2244
Don't forget the quotes for the string
type key.
{{total.get('test1')}}
Upvotes: 1
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