我想在输入文本框中保留一些搜索历史记录,然后在输入字段中输入autocomplete =“on”属性,但只有在重新加载或刷新页面时它才有效。
这是我在app.js中引用localStorage方法的内容,我可以保存输入历史记录控制台,如[“123123”,“123123”,“abc123”,“dkiwksiwdADS”,“33333”,“555555”,“ QWQWQWQW“],但是如何在文本框中双击这些保存的历史记录(可能是index.html中的div)??
我的代码: app.js:
......
search.getHistory = function() {
console.log($window.localStorage.myObj);
}
search.runreportsearch = function () {
var history;
if ($window.localStorage.myObj){
history = JSON.parse($window.localStorage.myObj);
if (angular.isArray(history)){
history.push(search.searchboxinput);
} else {
history = [];
history.push(search.searchboxinput);
}
$window.localStorage.myObj=JSON.stringify(history);
console.log($window.localStorage.myObj);
} else {
history = [];
history.push(search.searchboxinput);
$window.localStorage.myObj=JSON.stringify(history);
console.log($window.localStorage.myObj);
index.html
<div class="col-sm-6">
<h4><input type="text" class="form-control text-center" ng-model="search.searchboxinput" ng-dblclick="search.getHistory()" placeholder="Enter term to search"/></h4>
</div>