我需要使用Angular本地存储来存储表单数据。填写表单时,我需要将数据存储到本地存储,然后在
标记中查看。这是我的代码:
<form data-ng-submit="makeNote()" class="todo-form">
<input type="text" data-ng-model="noteText" placeholder="Enter new ToDo item" />
<br />
<input type="submit" value="Add Note" />
</form>
<p>{{noteData}}</p>
&#13;
var noteStorageKey = 'area' + areaId + 'climb' + climbId + 'noteStore';
// Local Storage for Notes
$scope.makeNote = function() {
var noteToSave = $scope.noteText;
$localStorage[noteStorageKey] = noteToSave;
$scope.noteData = noteToSave;
}
$scope.noteMyData = function() {
$scope.noteData = $localStorage[noteStorageKey];
}
$scope.removeNote = function() {
delete $localStorage[noteStorageKey];
$scope.noteData = '';
}
&#13;
注意:长存储密钥用于存储每页的特定密钥。