javascript - 如何将文本字段中的输入保存到本地存储中,然后在 Angular 中单击按钮后在列中显示项目
问题描述
我如何将用户输入存储到待办事项数组中,然后存储到本地存储中,然后显示到待办事项列中。如何将文本字段中的输入保存到本地存储中,然后在 Angular 中单击按钮后在列中显示项目。
模板:
<div cdkDropListGroup>
<div class="example-container">
<h2>TO DO</h2>
<div
cdkDropList
[cdkDropListData]="todo"
class="example-list"
(cdkDropListDropped)="drop($event)">
<div class="example-box" *ngFor="let item of todo" cdkDrag>{{item}}</div>
</div>
</div>
<div class="example-container">
<h2>IN PROGRESS</h2>
<div
cdkDropList
[cdkDropListData]="inprogress"
class="example-list"
(cdkDropListDropped)="drop($event)">
<div class="example-box" *ngFor="let item of inprogress" cdkDrag>{{item}}</div>
</div>
</div>
<div class="example-container">
<h2>DONE</h2>
<div
cdkDropList
[cdkDropListData]="done"
class="example-list"
(cdkDropListDropped)="drop($event)">
<div class="example-box" *ngFor="let item of done" cdkDrag>{{item}}</div>
</div>
</div>
</div>
<form >
<mat-form-field class="example-full-width">
<mat-label>New task</mat-label>
<input
matInput placeholder="Ex. Check email"
*ngFor="let item of todo">
</mat-form-field>
<button mat-mini-fab color="primary" (Click)="onAdd()">+</button>
drag and drop columns from Angular material UI in template.
ts file:
export class AppComponent {
title = 'task-board';
todo = ['new task'];
inprogress = [
'Get to work',
'Pick up groceries',
'Go home',
'Fall asleep'
];
done = [
'Get up',
'Brush teeth',
'Take a shower',
'Check e-mail',
'Walk dog'
];
drop(event: CdkDragDrop<string[]>) {
if (event.previousContainer === event.container) {
moveItemInArray(event.container.data, event.previousIndex, event.currentIndex);
} else {
transferArrayItem(event.previousContainer.data,
event.container.data,
event.previousIndex,
event.currentIndex);
}
}
我如何添加正确的逻辑来存储和显示到待办事项中。
解决方案
推荐阅读
- python-3.x - 运行迁移时出现 sqlalchemy.exc.ArgumentError
- amazon-web-services - SQS 延迟是否适用于 FIFO 队列的队列级别或消息组级别?
- jquery - 使用 load() 在 Jquery 中仅查找并加载第 n 个 div
- github - 按唯一用户过滤提交
- api - 如何使用 api 将事件从 misp 导出到 csv 文件
- python - AttributeError:“LineCollection”对象没有属性“do_3d_projection”
- excel - 限制可以选择下拉列表中每个选项的次数
- java - java.lang.ClassNotFoundException:org.eclipse.core.runtime.adaptor.EclipseStarter raspberrypi 不工作
- python - 将内部python函数放在代码的底部
- python - 除非在任何函数之前调用 basicConfig,否则不会创建 Python 日志文件