I use ionic, and I have a select where I choose one of two options for performing arithmetic operations with them after. Use ngStorage to save, but I would also apply to the select the option itself and always keep the user chooses in ngStorage supporting me as I do with the input of "write a number", any help?
http://codepen.io/maestromutenrroy/pen/ivgIH
angular.module('ionicApp', ['ionic','ngStorage'])
.controller('MainCtrl', function($scope, $localStorage) {
$scope.$storage = $localStorage.$default({
c6: 1,
c12: 2
});
$scope.results = {};
$scope.templates = [{
name: '5',
url: 'template1.html'
},
{
name: '10',
url: 'template2.html'
}];
$scope.template = $scope.templates[1];
})
Thank you!
In your codepen, you are binding the number input using $storage:
<input type="number" ng-model="$storage.c6" ...>
This will make the value of the input field persist between page reloads. However, you bind the to a $scope variable which is not part of $storage:
<select ng-model="template" ...>
so this value is reset to default when the page is reloaded.
To have the stay on the last selected option you need to store your "template" variable in $storage too.