1
I am creating a simple application in Angularjs, the application boils down to 3 pages:
- Apparatus: Where the person chooses the apparatus
- Plans: Choose the plane related to the device
- Final registration informing name, email, phone and etc...
The list of possible devices and plans for that chosen device comes from a JSON file, which I pick up through an HTTP request
The question is: I would like to go saving this information, when it clicks on a device, then the plan and save and after writing the data
saved everything and left on the end page and a console.log
, but how do I do it?
This is my file api.js, where I request the devices:
// plataformas
//arquivo api.js
app.controller('plataformAPI', function($scope, $http){
$http.get('http://private-59658d-celulardireto2017.apiary-mock.com/plataformas')
.then(function(response){
$scope.dados = response.data.plataformas;
});
});
This is the file home html., where the person chooses the apparatus:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12" align="center" ng-controller="plataformAPI">
<div ng-repeat="x in dados">
<h1>{{x.nome}}</h1>
<p>{{x.descricao.replace('|',' ')}}</p>
<p><a class="btn btn-primary btn-md" href="{{prefix + x.nome}}" role="button">Quero esse</a></p>
</div>
</div>
I came to create the following scheme, but it didn’t work, saved in localstorage
as undefined
:
// click event
$scope.eventos = {};
$scope.eventos.Clique = function() {
var nomeAparelho = document.getElementsByClassName('nomeAparelho').value;
localStorage.setItem("aparelho:", nomeAparelho);
}
});