Javascript 如何使用Angular 2更改按钮单击时输入标记的禁用属性
我正在尝试使用Angular 2更改按钮单击时标记的禁用属性。到目前为止,我可以禁用它一次,但我想切换这个功能来回 这是我的HTML模板代码Javascript 如何使用Angular 2更改按钮单击时输入标记的禁用属性,javascript,html,angular,angular2-template,Javascript,Html,Angular,Angular2 Template,我正在尝试使用Angular 2更改按钮单击时标记的禁用属性。到目前为止,我可以禁用它一次,但我想切换这个功能来回 这是我的HTML模板代码 <div *ngIf = "hero"> <h2> {{hero.name}} details! </h2> <button (click)="goBack()">Back </button> <button (cli
<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>
这是我当前使用的console.log浏览器,用于显示我的属性值正在更改。
指令的右侧需要是一个
布尔值。“disabled”
和“abled”
都是真实值。因此,其计算结果为[disabled]=“true”
例如:
if(this.editOn)
{
this.editOn = false;
this.change = false;
console.log("Change propery status: ", this.change);
return this.change;
}else if (!this.editOn)
{
this.editOn = true;
this.change = true;
console.log("Change propery status: ", this.change);
return this.change;
}
非常感谢您的解决方案!这帮了大忙@爱德华·穆德鲁很高兴我能帮忙:-)
if(this.editOn)
{
this.editOn = false;
this.change = false;
console.log("Change propery status: ", this.change);
return this.change;
}else if (!this.editOn)
{
this.editOn = true;
this.change = true;
console.log("Change propery status: ", this.change);
return this.change;
}