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爲空。不明白問題是什麼。我錯過了什麼嗎?