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 ?
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.
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!
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.
The $ in AngularJs is a built-in object.It contains application data and methods.
You can just use {{nameMap[key]}}
The correct answer would be to use nameMap.get(key)
as of Angular 2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With