user6579134 user6579134 - 3 months ago 19
AngularJS Question

place localstorage value in a textbox from a controller with angularjs

I have a localstorage value which i would want to put in it a texfield from a controller

.controller('working_ctrl', ['$scope', '$http', '$location', function ($scope, $http,$location) {
$scope.user= localStorage.getItem("user")
$scope.items = [];
$scope.selected = undefined;
$http({
method: 'GET',
url:'http://localhost/work/templates/spree/work/items.php'
}).then(function (data) {
$scope.items = data.data;
//console.log(JSON.stringify(data));

})
}])


HTML

<div ng-controller="working_ctrl" ng-repeat="s in items| limitTo:1">
<input name="quantity" type="text" id="quantity" ng-model="s.quantity">
<input name="user" type="text" id="user" ng-model="s.user">
</div>

Answer

You can bind the $scope.user to that textbox

<input name="user" type="text" id="user" ng-model="user">