11

I am a newer in angular. I am trying to learn to use angular js. I have a problem here. I have a map with name "nameMap" and its key->value following

    {
    1:su,
    2:mo,
    3:neptune
    }

what I want is when I get a key "key" such as "1", then display its mapped value "su" in page.

{{nameMap | key}}

I know I can do it if I achieve a filter myself. But I think this usage is so common that angular may do it with little code。 anyone who can help me ?

2 Answers 2

15

You can just use {{nameMap[key]}}

Sign up to request clarification or add additional context in comments.

2 Comments

I use Angular 2 and this didn't work. The answer from Mark worked for me.
That's doesn't work for types of Map<number, boolean> in Angular2+
13

The correct answer would be to use nameMap.get(key) as of Angular 2.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.