gpt4 book ai didi

javascript - 使用 angularjs 将本地存储值放在 Controller 的文本框中

转载 作者:行者123 更新时间:2023-11-30 09:45:42 25 4
gpt4 key购买 nike

我有一个本地存储值,我想将其放入来自 Controller 的 texfield

.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>

最佳答案

您可以将 $scope.user 绑定(bind)到该文本框

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

关于javascript - 使用 angularjs 将本地存储值放在 Controller 的文本框中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38993407/

25 4 0