AngularJS operation key-value objects are similar to java's hashmap (fill-in summary) and angularjshashmap
Preface:
We know that the most commonly used hashmap in java is put (...), get (...) and how to create (use) such an object in angularJS
Train of Thought Analysis:
We know that in java, chained access and "[]" can be used to access a value 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] = object;},remove: function (key) {delete map[key];}};})
4. Verify
1. Write
ParamsServices.put("itv", "itv");ParamsServices.put("itv2", "itv2");iParamsServices.put("itv3", "itv3");iParamsServices.put("itv4", "itv4");
2. Read
ParamsServices.get("itv") == ParamsServices.get("itv2") // trueiParamsServices.get("itv3") == iParamsServices.get("itv4") // false
5. Conclusion:
We recommend that you use method 2 to implement angul as a key value object (hashmap ).
The above section describes the AngularJS operation key-value object similar to the hashmap of java. I hope it will help you. If you have any questions, please leave a message.