I am creating a simple application in AngularJS, the application is summarized in 3 pages:
The list of possible devices and plans for that chosen device comes from a JSON file, which I get through an HTTP request.
The question is: I would like to save this information, when it clicks on a device, then the plan and save and after writing the data
save all and exit the final page and console.log
, but how do I do this?
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 home.html file where the person chooses the devices:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script><divclass="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 up with the following schema but it did not work, saved in localstorage
as undefined
:
// click event
$scope.eventos = {};
$scope.eventos.Clique = function() {
var nomeAparelho = document.getElementsByClassName('nomeAparelho').value;
localStorage.setItem("aparelho:", nomeAparelho);
}
});