我正在编写.todo任务管理器在Angular2..必须更新选择选项值…在localStorage
i am coding ..todo task manger in Angular2.... having to update select option value ....in localStorage
这是我关于待办事项管理的问题。当(change)事件被触发时,我想在select selector中更新一个选项值。
有2个组件//app.component.ts
//array object
this.dataArr[this.counter] = {id: this.task_ID, name: this.t_name, msg: this.t_msg, date: this.task_date};
//console.log(this.counter);
console.log(this.dataArr[this.counter]);
//local storage
if (typeof(Storage) !== "undefined") {
localStorage.setItem("taskM", JSON.stringify(this.dataArr.reverse())); //put object array in reverse order to show latest object at top position
this.myObj = JSON.parse(localStorage.getItem("taskM"));
}
在这个组件中,我想更改并保存选择选项值为localStorage
//task-form.component.ts。
import { Component, OnInit, Input, Output } from '@angular/core';
import { AppComponent } from './app.component';
@Component({
selector: 'task-data',
template: `<h3>List of Task</h3>
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>Task Id</th>
<th>Task Title</th>
<th>Description</th>
<th>Date</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let hero of taskMM">
<td> {{ hero.id }} </td>
<td> {{ hero.name }} </td>
<td> {{ hero.msg }} </td>
<td> {{ hero.date }} </td>
<td>
<select class="form-control">
<option *ngFor="let p of taskStatus"[value]="p"> {{p}}</option>
</select>
</td>
</tr>
</tbody>
</table>
</div>
`
})
export class TaskFormComponent {
taskStatus: string[];
taskMM: string[] = JSON.parse(localStorage.getItem("taskM"));
@Input('task-s') t_status: string;
@Input() data1: any= [];
onChange(deviceValue) {
console.log(deviceValue);
}
ngOnInit() {
console.log('this is ngOnInit ');
}
constructor() {
this.taskStatus = ['Started', 'Pending', 'Completed'];
}
}
<select (change)="onChange($event.target.value)" class="form-control">
<option *ngFor="let p of taskStatus"[value]="p"> {{p}}</option>
</select>
onChange($event) {
localStorage.setItem("taskM", $event);
}
相关文章:
- jQuery基于下拉选择更新帮助文本
- 为动态选择框选择更新功能
- AngularJS绑定模型以选择更新输入数字字段,最小值为最大值
- 4下拉菜单,在搜索之前根据选择更新每个菜单
- 如何根据下拉选择更新(追加到其中)href
- JavaScript>on更改输入&选择更新文本区域
- 如何根据用户选择更新我的税款
- 使用右键单击选择更新上下文菜单
- AngularJS选择的插件,选择:更新不起作用,在浏览器中工作
- 根据下拉列表中的选择更新文本字段(角度JS)
- Jquery 选择更新追加选择
- 基于下拉选择更新图表-javascript
- 使用路径线选择更新图案
- 如何根据下拉选择框中的选择更新sql数据库中的特定记录
- 根据另一个选择更新选择菜单
- 如何根据模态选择更新输入
- 根据用户选择更新下拉菜单值
- 我如何创建一个下拉菜单,当选择更新输入字段
- Javascript下拉菜单根据用户的选择更新价格
- 我如何使下拉列表选择更新网页上的图像