这是我的html更新按钮代码。 updateItem是我的方法,当我点击更新这个方法将起作用。
(button start)
button class="button" type="submit" *ngIf="update" (click)="updateItem(dashboard.value)" [disabled]="formDate.untouched &&formTask.untouched &&formDescription.untouched">Update(button end)
这是我的dashboard.component.ts文件
edit(taskname:string){
this.update=true;
let fetchArray= JSON.parse(window.localStorage.getItem('key'));
this.editItem = fetchArray.filter(fetchArray => fetchArray.taskname == taskname);
this.taskname=this.editItem[0].taskname;
this.date=this.editItem[0].date;
this.description=this.editItem[0].description;
this.updateval=this.editItem[0].taskname;
}
updateItem(form: any):void{
this.update=false;
this.taskname=form.taskname;
this.date=form.date;
this.description=form.description;
form.taskname=this.updateval;
this.taskUpdate=form.taskname;
let inLocalStorage= JSON.parse(window.localStorage.getItem('key'));
let itemUpdate={ "taskname":this.taskname , "date": this.date, "description": this.description};
var j;
for(var i=0; i< inLocalStorage.length; i++)
{
if (this.taskUpdate == inLocalStorage[i].taskname)
{
j=i;
}
}
this.myArray.splice(j,1,itemUpdate);
window.localStorage.setItem('key',JSON.stringify(this.myArray));
this.match= JSON.parse(window.localStorage.getItem('key'));
}
when I click on edit button update button will show after click on update it will be disabled.
我希望每次点击编辑按钮更新都应该被禁用
答案 0 :(得分:0)
作为模板驱动形式,那么你应该有html,如下所示
<input type="text" name="name" [(ngModel)]="model.task" #formTask="ngModel" required>
如果您具有上述html,则按钮标记将类似于
button class="button" type="submit"
..other code
[disabled]="!formDate.dirty && !formTask.dirty && !formDescription.dirty
检查dirty
标志,该标志告诉您元素是否已修改,因为untouched
没有帮助,只是检查您是否触摸了元素。