📜  localstorage getitem angular - TypeScript 代码示例

📅  最后修改于: 2022-03-11 14:48:11.478000             🧑  作者: Mango

代码示例3
// Parse any JSON previously stored in allEntries
  var existingEntries = JSON.parse(localStorage.getItem("store_owner_ad_contacts"));
  if(existingEntries == null) existingEntries = [];

  var adId = {
    "id":$scope.adId
  };
  // Save allEntries back to local storage
  existingEntries.push(adId);
  localStorage.setItem("store_owner_ad_contacts", JSON.stringify(existingEntries));

  var values = JSON.parse(localStorage.getItem("store_owner_ad_contacts"));
  angular.forEach(values, function(value, key) {

  // ^ This is coming as an object how can I get the key value?

   if(value == adId){
   //form has been submitted before
   }else{
   // showformVar = true 

    console.log(key + ': ' + value);
  });