Objective:
We know that the most used Java HashMap is put (...), get (...) and the Remove () method, how do you create (use) such an object in Angularjs?
Thinking Analysis:
We know that in Java you can use chained access and "[]" to access one of the values of HashMap
Specific implementation:
Chained access:
. Factory (' Paramsservices ', function () {
var params = {};
return {
get:function (key) {return
Params.key
},
put:function (Key, object) {
Params.key = object;
},
remove:function (key) {
delete params.key;}}
)
"" "Access:
. Factory (' Iparamsservices ', function () {
var map = {};
return {
get:function (key) {return
Map[key];
},
put:function (Key, object) {
Map[key] = Obje CT;
},
remove:function (key) {
delete map[key];}}
)
4. Verify
1. Write
Paramsservices.put ("ITV", "ITV");
Paramsservices.put ("ITV2", "ITV2");
Iparamsservices.put ("ITV3", "ITV3");
2. Read
Paramsservices.get ("ITV") = = Paramsservices.get ("ITV2")//True
iparamsservices.get ("itv3") = = Iparamsservices.get ("ITV4")//False
5. Summary:
Angul as a key value object (HASHMAP) recommended by the way to implement
The above is a small set to introduce the ANGULARJS operation of the key value object similar to Java HashMap (landfills summary), I hope to help you, if you have any questions welcome to my message.