问题描述
我正在使用p日历进行日期选择。现在,我想基于条件设置类属性。对于set属性,我正在使用setElementAttribute函数,但是它给了我错误'vendor.bundle.js:70655 TypeError: Cannot read property 'setAttribute' of undefined '
。它适用于普通输入或选择标签,但不适用于p日历标签。
这是HTML代码
<p-calendar [showIcon]="true"
name="date"
id="dateId"
#date
[(ngModel)]="dateValue"
[required]="isRequired"
autoClear="true"
(onSelect)="selectedDate(date.value)"
[ngModelOptions]="{standalone: true}"
(data)="refreshValue($event)"
dateFormat="mm/dd/yy"
hourFormat="24">
</p-calendar>
这是ts文件代码
@ViewChild('date ') date : any;
selectedDate(date) {
if (date != null) {
this._renderer.setElementAttribute(this.date.nativeElement,'class','form-control ng-pristine ng-valid ng-touched');
} else {
if(this.isRequired){
this._renderer.setElementAttribute(this.date.nativeElement,'form-control ng-touched ng-dirty ng-invalid');
this.Flag = false;
}
}
}
这是错误
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)