Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i get the value in a map by key in angular js

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 ?

like image 598
neptune Avatar asked Jul 12 '13 14:07

neptune


People also ask

How do you find the specific value of a key on a Map?

HashMap get() Method in Java util. HashMap. get() method of HashMap class is used to retrieve or fetch the value mapped by a particular key mentioned in the parameter. It returns NULL when the map contains no such mapping for the key.

How do I Map a key value pair in typescript?

To define a Map with array values in TypeScript, type the map to have keys of a specific type and set the values to have an array type, e.g. const map1 = new Map<number, string[]>() . All of the key-value pairs in the Map must conform to the specified type. Copied!

What is Map key value?

Key value maps (KVMs) are ideal for this. A KVM is a custom collection of encrypted key/value String pairs. The following lists three broad use cases for storing data in KVMs: User session data: Data that is created and deleted by the runtime only; you cannot view or manage KVM entries outside of the runtime.

What is $$ in AngularJs?

The $ in AngularJs is a built-in object.It contains application data and methods.


2 Answers

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

like image 139
rooftop Avatar answered Oct 08 '22 16:10

rooftop


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

like image 42
Mark Avatar answered Oct 08 '22 14:10

Mark