I was given the task of storing contacts from the form to localstorage. What is the best way to do this? I have tried several options but it is not clear to me which value should be for value and which for key? This is the script.js code:
var app = angular.module("addrBook",[]);
app.controller("myCtrl",function($scope){
$scope.info = [
{name:"Pera",tel:"2145466547457"},
{name:"Sima",tel:"534654756865634"},
{name:"Mika",tel:"2355765864578"}
];
$scope.addMe = function(){
return {
name: $scope.newName,
tel:$scope.newTel
}
}
$scope.addItem = function(){
for(var i=0;i<$scope.info.length;i++){
if(($scope.info[i].name == $scope.addMe().name)||
($scope.info[i].tel == $scope.addMe().tel)){
alert("name or telphone number was repeated");
return false;
}
}
$scope.info.push($scope.addMe());
}
$scope.removeItem = function(){
$scope.info.splice(this.$index,1)
}
$scope.change = function(){
index = this.$index;
$scope.showMe = function(indx){
if(indx == index){
return true;
}
}
}
$scope.save = function(){
index = this.$index;
$scope.showMe = function(indx){
if(indx == index){
return false;
}
}
}
})