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>
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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.