I am working on a feature where I need to store data in local storage multiple times using a dropdown menu and some input fields. Currently, I am able to retrieve all the values from the input fields and see them in the console log. My goal is to save these inputs into local storage as an object when the "Save" button is clicked. After changing the options and clicking again, I want to save another object in local storage.
https://i.sstatic.net/T4bjG.jpg
browse.html
<ion-view view-title="Browse">
<ion-content>
<select id="vrstaribe" ng-model="selekt" ng-options="r as r for r in ribe" selected>
<option value="">Vrsta ribe</option>
</select>
<label class="item item-input">
<input id="tezina" type="number" placeholder="Tezina">
</label>
<label class="item item-input">
<input id="mamac" type="text" placeholder="Mamac">
</label>
<button class="button button-positive" ng-click="spremi()">Spremi</button>
</ion-content>
</ion-view>
contollers.js
.controller('SpremiCtrl', function($scope) {
var ulov = {vrstaribe: '', tezina: '', mamac: '' };
var popisulova = [];
$scope.ribe = ["Saran", "Stuka", "Som"];
$scope.spremi = function() {
var vr = document.getElementById('vrstaribe');
var rib = vr.options[vr.selectedIndex].text;
var tez = document.getElementById('tezina').value;
var mam = document.getElementById('mamac').value;
console.log("Riba : " + rib + '\n' + "Težina : " + tez + '\n' + "Mamac : " + mam);
ulov.vrstaribe = rib;
ulov.tezina = tez;
ulov.mamac = mam;
popisulova.push(ulov);
console.log(ulov);
localStorage.setItem('ulov', JSON.stringify(ulov));
var vrati = localStorage.getItem('ulov');
//console.log('Ulov: ', JSON.parse(vrati));
console.log(ulov);
}
})