获取localstorage值并放入文本框中

时间:2016-08-06 21:48:49

标签: javascript angularjs html5

我有一个名为item的文本框,当页面加载时,我想从localstorage获取一个值并将其放在文本框item中,我稍后将其发送到数据库。

HTML:

<div ng-controller="newitem_ctrl">
  <input name="item" type="text" id="item" placeholder="Name of Item" ng-model="item" required="required">
</div>

JS:

.controller('newitem_ctrl', function($scope,$http,$location,$ionicLoading,$ionicPopup, $timeout){
  $scope.item = localStorage.getItem("shop_id")

  $scope.insertnew = function() {
    $ionicLoading.show({template: '<p>Adding...</p><ion-spinner></ion-spinner>'});
    event.preventDefault();
    $http.post("http://localhost/myweb/insert.php",
    {'item':$scope.item,'quantity'})
    .success(function(data,status,headers,config){
      console.log(data)
      {$ionicLoading.hide();}
    }).error(function(error){
      console.error(error);
    });
  }
})

0 个答案:

没有答案