Reputation: 1
I want to get the value of angular and store it in my local storage. something like this:
<input type="text" id="ID" value="{{sudent.id}}">
<script>
localStorage.setItem("STUDID", document.getElementById("ID").value);
</script>
and I want the result to be:
<script>
localStorage.setItem("STUDID", "HUMMS-201906");
</script>
Upvotes: 0
Views: 118
Reputation: 7899
use ng-model
so as to provide two-way data binding and in controller access the ng-model value using $scope
.
angular.module('inputExample', [])
.controller('ExampleController', ['$scope', function($scope) {
$scope.student = {
"id": 101
};
console.log($scope.student.id);
}]);
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<body ng-app="inputExample">
<div ng-controller="ExampleController">
<input type="text" name="studentId" ng-model="student.id" required>
</div>
</body>
Upvotes: 1