【发布时间】:2017-11-15 07:47:19
【问题描述】:
我正在尝试使用 Angular 2 在单击按钮时更改标签的 disabled 属性。到目前为止,我可以将其禁用一次,但是我想来回切换此功能。
这是我的 HTML 模板代码。
<div *ngIf = "hero">
<h2> {{hero.name}} details! </h2>
<button (click)="goBack()">Back </button>
<button (click)="edit()"> Edit </button>
<button (click)="save()">Save </button>
<div><label> Id: </label> {{hero.id}} </div>
<div>
<label> Name: </label>
<input [(ngModel)] = "hero.name" placeholder = "name"
[disabled]="change" />
</div>
</div>
这是我的组件中的代码
hero: Hero;
editOn: boolean = true;
change: string;
edit(): string
{
if(this.editOn)
{
this.editOn = false;
this.change = "abled";
console.log("Change propery status: ", this.change);
return this.change;
}else if (!this.editOn)
{
this.editOn = true;
this.change = "disabled";
console.log("Change propery status: ", this.change);
return this.change;
}
这是我目前使用 console.logs 的浏览器,用于显示我的属性值正在发生变化。 Broswer Image
【问题讨论】:
标签: javascript html angular angular2-template