我是不熟悉角度和前端编程的,所以很抱歉。
我有一个HTML
文件,看起来像这样
<input class="born-date-input" formControlName="dateOfBorn" minlength="1" maxlength="10" (click)="inputClick=true"/>
<div class="alert alert-warning" *ngIf="inputClick==true">
<small>show warning</small>
</div>
在我的.ts组件文件中
export class MainInputFormComponent implements OnInit, DoCheck {
@Output('changeData') sendTheNewDataJSON = new EventEmitter<any>();
private inputClick: boolean = false;
}
在HTML文件中看不到inputClick
变量
答案 0 :(得分:4)
如果您将其声明为私有,则不会发生数据绑定。您需要将其声明为public
才能使其可用。请遵循以下代码:
export class MainInputFormComponent implements OnInit, DoCheck {
@Output('changeData') sendTheNewDataJSON = new EventEmitter<any>();
public inputClick: boolean = false;
}
然后您可以像这样在HTML中使用它。
<input class="born-date-input" formControlName="dateOfBorn" minlength="1" maxlength="10" (click)="inputClick=true"/>
<div class="alert alert-warning" *ngIf="inputClick">
<small>show warning</small>
</div>
答案 1 :(得分:2)
将“私人”更改为“公共”或删除访问修饰符(默认情况下为公共)
export class MainInputFormComponent implements OnInit, DoCheck {
@Output('changeData') sendTheNewDataJSON = new EventEmitter<any>();
inputClick: boolean = false;
}
答案 2 :(得分:1)
您可以执行上述任一操作,因为在将inputClick声明为私有后无法访问
export class MainInputFormComponent implements OnInit, DoCheck {
@Output('changeData') sendTheNewDataJSON = new EventEmitter<any>();
inputClick: boolean = false;
}
或
export class MainInputFormComponent implements OnInit, DoCheck {
@Output('changeData') sendTheNewDataJSON = new EventEmitter<any>();
public inputClick: boolean = false;
}