1
我做了一个非常简单的页面,其中input
字段和button
。 当input
字段为空时,我必须将button
禁用。一旦用户点击它,输入字段将被清除或重置。 点击后我的按钮被禁用。但它从一开始就没有被禁用。 我的代码是:按钮在页面初始化时未被禁用,但在您单击它时被禁用
HMTL
<input type= 'text' [(ngModel)]="userName">
{{userName}}
<button[disabled]="userName==''(click)='resetUsername()'>RestUsername</button>
打字稿:
import {Component} from '@angular/core';
@Component({
selector : 'app-server',
templateUrl :'./server.component.html'
})
export class Servercl {
username=''
resetUsername = function(){
this.userName='';
}
}
请告诉我要去的地方错了。 Angular 4对我来说是新的。 我从头开始使userName为空。不明白问题是什么。我错过了什么吗?