I'm implementing angular js and is trying to get the input box's value and store it into the local storage. The input is typed by user and it's refer to ip address.
Below is my html code:
<div>
<input ng-model="serverip">
<input type="button" class="button" value="Apply" ng-click="save()">
</div>
Below is my js code:
.controller('Ctrl', function($scope) {
$scope.save= function() {
console.log($scope.serverip);
localStorage.setItem('serverip', $scope.serverip);
};
})
Why is it by using the above coding, after I key in the ip address into the input box, the $scope.serverip
I get is always undefine?
I kinda find out the correct answer. We have to pass back the serverip
in the html:
<div>
<input ng-model="serverip">
<input type="button" class="button" value="Apply" ng-click="save(serverip)">
</div>
And in the js file:
.controller('Ctrl', function($scope) {
$scope.save = function(serverip) {
console.log(serverip);
localStorage.setItem('serverip', serverip);
};
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With